SQL20、分组排序练习题

思路:要查看不同学校的情况可以使用GROUP BY进行分组,然后对结果升序排序可以使用ORDER BY关键字

代码解释:从表user_profile中取出列university和平均发帖数,然后对结果进行分组并升序排列

SELECT 
  university, 
  AVG(question_cnt) AS avg_question_cnt
FROM 
  user_profile
GROUP BY 
  university
ORDER BY 
  avg_question_cnt

题目:https://www.nowcoder.com/practice/e00bbac732cb4b6bbc62a52b930cb15e?tpId=199&tags=&title=&difficulty=0&judgeStatus=0&rp=0&sourceUrl=%2Fexam%2Foj%3Fpage%3D1%26tab%3DSQL%25E7%25AF%2587%26topicId%3D199

posted @ 2022-07-11 12:55  tiansz  阅读(22)  评论(0编辑  收藏  举报