select count(*) from table1 group by id你这句查出来的结果应该是: 1 2 1 吧
你再仔细检查一下输入和输出。当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项。
select id from table1 group by id
select count(*) from table1 group by id对!查出来的结果是 1 2 1 我写错了!但是我想得到一个3! 这个3就是行数!就是有3行!
select count( distinct id) from table1
select count( distinct id) from table1得到的结果是 1 1 1
错了!我写错了!我后面还加了个group by还是ACMAIN_CHM前辈帮我解决!谢谢了!
晕,如果你就想简单得到个3,就直接:select count(1) from table1;
顺便问下斑竹,select distinct count(id) from table1; select count(distinct id) from table1;上面2句有什么区别没?
是啊!select distinct count(id) from table1; select count(distinct id) from table1; 这两句话是有区别!为什么那!
select count(*) from table1 group by id你这句查出来的结果应该是:
1
2
1
吧
1
2
1
也就是说ID为1的有一项,ID为2的有2项,ID为3的有1项。
select count(*) from table1 group by id对!查出来的结果是
1
2
1
我写错了!但是我想得到一个3! 这个3就是行数!就是有3行!
select count( distinct id) from table1得到的结果是
1
1
1
select count(distinct id) from table1;上面2句有什么区别没?
select count(distinct id) from table1;
这两句话是有区别!为什么那!