blog迁移至
:http://www.micmiu.com
select count (*)、count(1)、count(column)的区别如下:
-
count(1) 中的 1 并不是表示为第一个
column
-
count(*) 跟 count(1) 的结果一样,包括对NULL的统计
-
count(column) 是不包括对NULL的统计
-
如果表沒有主键(Primary key), 那么count(1)比count(*)快
-
如果表没有主键,只建了索引,那么count(*),count(1)是一样的,都是TABLE ACCESS FULL
,而count(索引)则是INDEX FULL SCAN
-
如果有主键的話,那count(主键)最快,那么count(*),count(1),以及count(主键)是一样的,都是INDEX FULL SCAN
-
如果你的表只有一个字段的话那count(*)就是最快的
亦可参考下官网上的有关问答:
本文连接:http://sjsky.iteye.com/blog/1209560
转载请注明来自:Michael's blog @ http://sjsky.iteye.com
----------------------------- 分 ------------------------------ 隔 ------------------------------ 线 ------------------------------
分享到:
相关推荐
select count(*), cid, sex from student group by cid, sex having cid > 1 and max(cid) > 2; Ø 嵌套子查询 子查询是一个嵌套在select、insert、update或delete语句或其他子查询中的查询。任何允许使用表达式的...
[debug] http://www.rayner.com/products.php?id=22/**/AND/**/1=2/**/UNION/**/SELECT/**/1,concat(0x1e,0x1e,COUNT(*),0x1e,0x20),3,4,5,6,7,8,9 ,10/**/FROM/**/db2889_rayner_en.auth/**/WHERE/**/pass=0x...
总数:select count * as totalcount from table1 求和:select sum(field1) as sumvalue from table1 平均:select avg(field1) as avgvalue from table1 最大:select max(field1) as maxvalue from table1 ...
select @m=case when @m between 1 and 3 then 1 when @m between 4 and 6 then 4 when @m between 7 and 9 then 7 else 10 end select @time=datename(year,@date)+'-'+convert(varchar(10),@m)+'-01' ...
select count(*) from tab1,tab2 执行时间0.96秒 选择TAB2作为基础表 (不佳的方法) select count(*) from tab2,tab1 执行时间26.09秒 如果有3个以上的表连接查询,那就需要选择交叉表...
from score a left join ( select a.s_score from Score a group by a.s_score having count(a.s_score)>1 and count(distinct a.c_id) > 1)tt on tt.s_score=a.s_score group by a.s_id select distinct a.s_...
2.SELECT column1, column2, column3 FROM table_name; (查询表中指定列的数据) 3.SELECT * FROM table_name WHERE condition; (查询表中符合条件的数据) 4.SELECT COUNT(*) FROM table_name; (统计表中数据总数)
总数:select count as totalcount from table1 求和:select sum(field1) as sumvalue from table1 平均:select avg(field1) as avgvalue from table1 最大:select max(field1) as maxvalue from table1 最小:...
总数:select count(*) from table1; 求和:select sum(field1) from table1; 平均:select avg(field1) from table1; 最大:select max(field1) from table1; 最小:select min(field1) from table1; 排序:select ...
select max(column_b) from tablename group by column1,column2,...) alter table tablename drop column column_b 20、说明:列出数据库里所有的表名 select name from sysobjects where type='U' // U代表用户 21...
select max(column_b) from tablename group by column1,column2,...) alter table tablename drop column column_b 20、说明:列出数据库里所有的表名 select name from sysobjects where type='U' // U代表用户 21...
select max(column_b) from tablename group by column1,column2,...) alter table tablename drop column column_b 20、说明:列出数据库里所有的表名 select name from sysobjects where type='U' // U代表用户 21...
select max(column_b) from tablename group by column1,column2,...) alter table tablename drop column column_b 20、说明:列出数据库里所有的表名 select name from sysobjects where type='U' // U代表用户 ...
总数:select count as totalcount from table1 求和:select sum(field1) as sumvalue from table1 平均:select avg(field1) as avgvalue from table1 最大:select max(field1) as maxvalue from table1 最小:...
* 返回记录总数, 使用方法: getAllCount("SELECT count(ID) from tableName") 2004-06-09 * 可滚动的 Statement 不能执行 SELECT MAX(ID) 之类的查询语句(SQLServer 2000) * * @param sql * 需要执行的 SQL *...
总数:select count as totalcount from table1 求和:select sum(field1) as sumvalue from table1 平均:select avg(field1) as avgvalue from table1 最大:select max(field1) as maxvalue from table1 最小:...
<select id="countAll" resultType="int"> select count(*) c from blog; </select> <select id="countSome" resultType="int" parameterType="String"> select count(*) c from blog ; </select> <select ...
方法1:sql2000查询语句 ---------------------------------- declare @objid int,@objname char(40) set @objname = 'a'--表名称 ...cxGrid1DBBandedTableView2.ColumnCount; dbgrid: DBGrid1.Columns.Count;
delphi数据库字段数量方法 方法1:sql2000查询语句 ---------------------------------- declare @objid int,@objname char(40) ...cxGrid1DBBandedTableView2.ColumnCount; dbgrid: DBGrid1.Columns.Count;
–count 统计 select count(*) from student; select count(sex) from student; select count(distinct sex) from student; –top 取前N条记录 select top 3 * from student; –alias column name