table1
id
 1
 2
 2
 3
select count(*) from table1 group by id查询出来是三行!
结果是
table1
count(*)
1
2
3我想得到是行数! 怎么能得到三行这个记录数那!请各位前辈指教!

解决方案 »

  1.   

    没看懂你想做什么select count(1) from table1;
      

  2.   


    select count(*) from table1 group by id你这句查出来的结果应该是:
    1
    2
    1
      

  3.   

    你再仔细检查一下输入和输出。当GROUP BY ID后,统计出来的是每个不同ID有多少个重复项。如果表里的ID有4个,分别是1 2 2 3,那么使用'SELECT COUNT( * ) FROM TABLE GROUP BY ID'的统计结果应该是
    1
    2
    1
    也就是说ID为1的有一项,ID为2的有2项,ID为3的有1项。
      

  4.   

    select   id from table1 group by id
      

  5.   


    select count(*) from table1 group by id对!查出来的结果是
    1
    2
    1
    我写错了!但是我想得到一个3! 这个3就是行数!就是有3行!
      

  6.   

    select count( distinct id) from table1
      

  7.   


    select count( distinct id) from table1得到的结果是
    1
    1
    1
      

  8.   

    错了!我写错了!我后面还加了个group by还是ACMAIN_CHM前辈帮我解决!谢谢了!
      

  9.   

    晕,如果你就想简单得到个3,就直接:select count(1) from table1;
      

  10.   

    顺便问下斑竹,select distinct count(id) from table1;
    select count(distinct id) from table1;上面2句有什么区别没?
      

  11.   

    是啊!select distinct count(id) from table1;
    select count(distinct id) from table1;
    这两句话是有区别!为什么那!
      

  12.   

    select count(distinct id) from table1;