max里面不是不能再套一个count嘛

select university,age,max(count(device_id)) max_cnt
from user_profile
group by university,age
order by max_cnt desc

这个我写的,报错

select age , max(cnt) max_cnt
from
(select age , university , count(*) cnt
from user_profile
group by age , university) t
group by age
order by max_cnt desc
这个答案
我想问,max里面不是不能再套一个count嘛,本想着group by两个字段。

你这两个查询结果不都不一样么,你写的是根据 university,age分组 下边最后结果是根据 age 分组

两个都是聚合函数 怎么套,都会压缩数据,只能分开来,count作为子表再聚合一次