我想计算计数和分组表结果的结果
就像我有一张桌子,a
:
id |name
1 |abc
2 |abc
3 |abc
4 |xyz
5 |xyz
我的查询是SELECT COUNT(id) as count_id from a GROUP BY name
...给出结果:
count_id
3
2
我想计算这个结果的总行数是2
所以我的查询是SELECT COUNT(SELECT COUNT(id) as count_id from a GROUP BY name) as maincount from a
...但它在phpmyadmin
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT count.....
答案 0 :(得分:5)
这样做:
SELECT COUNT(DISTINCT name) FROM a
答案 1 :(得分:2)
虽然可能更优雅,但是子选择会起作用。
Select count(*) from (SELECT COUNT(id) as count_id from a GROUP BY name) as b