经常用到select count(1) from .....
但是一直没明白为什么可以用count(1),表中也没有1这一列啊,count(2),count(3) 也一样都可以达到count(*)的效果, 各位位能具体解释这是什么意思吗?
但是一直没明白为什么可以用count(1),表中也没有1这一列啊,count(2),count(3) 也一样都可以达到count(*)的效果, 各位位能具体解释这是什么意思吗?
select * ,1 ,2,'a' from table
行数是一样的是吧
select Count(*) ,Count(1) ,Count(2),Count('a') from table
还是一样的
明白了吧
一樣啊
insert @t select '1900-1-2 00:00:00.000'
insert @t select '1900-1-2 00:00:00.001'
insert @t select '1900-1-2 00:00:00.009'
insert @t select '1900-1-2 00:00:00.002'
insert @t select '1900-1-2 00:00:00.003'
insert @t select '1900-1-2 00:00:00.004'
insert @t select '1900-1-2 00:00:00.005'
insert @t select '1900-1-2 00:00:00.006'
insert @t select '1900-1-2 00:00:00.007'
insert @t select '1900-1-2 00:00:00.008'select count(1) as '总行数'
from @t
结果:
总行数
10说明:1代表第一列,count(1)代表计算第一列有多少行。峥狼(Staid Yang)