select count(*) from A group by f1和select count(ic) from A group by f1哪个快

learningjsp 2006-12-06 12:39:43
表中记录千万行级的情况下,这两个语句哪个快些?
有没有更好的方法?
...全文
298 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
youqiong 2006-12-06
  • 打赏
  • 举报
回复
当然count(*)快
caixia615 2006-12-06
  • 打赏
  • 举报
回复
建议LZ用查询计划看看..
wanglv 2006-12-06
  • 打赏
  • 举报
回复
建议采用count(ic)方式
shuqinpeng 2006-12-06
  • 打赏
  • 举报
回复
mark
marco08 2006-12-06
  • 打赏
  • 举报
回复

count(*) --包括NULL
count(col1) --忽略NULL

create table T(col1 char(1))
insert T select 'A'
union all select 'A'
union all select 'N'
union all select 'B'
union all select 'B'
union all select NULL
union all select NULL

select col1, count(*) as num from T group by col1
--result
/*
col1 num
---- -----------
NULL 2
A 2
B 2
N 1

(4 row(s) affected)
*/

select col1, count(col1) as num from T group by col1
--result
/*
col1 num
---- -----------
NULL 0
A 2
B 2
N 1

(4 row(s) affected)
*/
lhb2000 2006-12-06
  • 打赏
  • 举报
回复
count(索引键)>count(0)>count(*)
sujinlin 2006-12-06
  • 打赏
  • 举报
回复
ic上有索引么
caomm2001 2006-12-06
  • 打赏
  • 举报
回复
count(*)快

34,593

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧