此代码非常适合获取各个组计数的摘要和总计的总和,但我只想要没有ROLLUP的各个国家的总计:
SELECT country, count( * )
FROM mytable
GROUP BY country
WITH ROLLUP
LIMIT 0 , 300
研究了很多例子,我希望这个例子能够最终发挥作用但没有乐趣(无法弄清楚代码中的MySQL错误):
SELECT country,COUNT(*)
FROM mytable
GROUP BY country
COMPUTE Sum(Count(*))
感谢您的帮助!
-stucko
答案 0 :(得分:0)
如果你想获得GROUP BY
返回的行数,你可以做这样的事情
SELECT COUNT(*) FROM (
SELECT country, count( * )
FROM mytable
GROUP BY country
) a /*derived tables need an alias*/