题解 | #分组计算练习题#
分组计算练习题
https://www.nowcoder.com/practice/009d8067d2df47fea429afe2e7b9de45
select gender, university, count(device_id) as user_num, avg(active_days_within_30) as avg_active_day, avg(question_cnt) as avg_question_cnt from user_profile group by gender, university order by gender;
请注意,目前众多题解里面没有最后一句“order by gender”,因此会导致输出结果乱序。
根据题意需要在分组后,需在分组的基础上进行排序。故需加上 order by gender,才能运行出最终结果。