题解 | #分组排序练习题#
分组排序练习题
http://www.nowcoder.com/practice/e00bbac732cb4b6bbc62a52b930cb15e
select university,
avg(question_cnt) as avg_question_cnt
from user_profile
group by university
order by avg_question_cnt;
使用的是order by
由于SQL语句执行顺序如下:
FROM - ON - JOIN - WHERE - GROUP BY - WITH - HAVING - SELECT - DISTINCT - ORDER BY - LIMIT
因此ORDER BY后应添加avg_qusetion_cnt,而不是聚合函数AVG(question_cnt)