经常用到select count(1) from .....
但是一直没明白为什么可以用count(1),表中也没有1这一列啊,count(2),count(3) 也一样都可以达到count(*)的效果,  各位位能具体解释这是什么意思吗?

解决方案 »

  1.   

    重点是求满足后面条件的行数 ,括号里面是什么不重要
    select * ,1 ,2,'a' from table 
    行数是一样的是吧
    select Count(*) ,Count(1) ,Count(2),Count('a') from table 
    还是一样的
    明白了吧
      

  2.   

    我知道效果是一样啊,除了count(null)不行,其他都行,为什么能够这样做呢?? 这才是我要问的
      

  3.   

    select 1,'123123' from tt
    一樣啊
      

  4.   

    增加一个常数列,select 1 from.....任何一个表
      

  5.   

    count(*) 和count(1或其他数字)区别是:count(*)是在满足条件下的记录数,count(1)当满足条件出现一次的时候就可做其他的事,主要用来判断
      

  6.   

    happyflystone(无枪的狙击手) 正解
      

  7.   

    declare @t table(date char(21))
    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)