select count(*) from student
group by branch
这个查询对我来说非常合适,我得到了这样的输出。
+----------+ | count(*) | +----------+ | 32 | | 27 | | 50 | | 52 | | 58 | | 57 | | 59 | +----------+
7行(0.00秒) 但是当我使用
时select max(count(*)) from student group by branch;
导致错误
错误1111:无效使用群组功能
请帮帮我。
我正在使用MySQL Cluster 7.3
答案 0 :(得分:1)
您无法嵌套聚合函数。您需要使用子查询。
SELECT MAX(c)
FROM (SELECT COUNT(*) AS c
FROM student
GROUP BY branch) AS t1
答案 1 :(得分:0)
您可以使用以下
SELECT COUNT(*) AS total FROM student GROUP BY branch ORDER BY total DESC LIMIT 1
或强>
将您当前的查询用作子查询
SELECT MAX(t.total) FROM (SELECT COUNT(*) AS total FROM student GROUP BY branch) AS t