题解 | 统计每个学校的答过题的用户的平均答题数

统计每个学校的答过题的用户的平均答题数

https://www.nowcoder.com/practice/88aa923a9a674253b861a8fa56bac8e5

SELECT
    university,
    ROUND(AVG(answer_cnt), 4) AS avg_answer_cnt
FROM
    (
        SELECT
            user_profile.university,
            user_profile.device_id,
            COUNT(question_practice_detail.question_id) AS answer_cnt
        FROM
            user_profile
            INNER JOIN question_practice_detail ON user_profile.device_id = question_practice_detail.device_id
        GROUP BY
            user_profile.university,
            user_profile.device_id
    ) join_table
	# 1 以山东大学为例子,山东大学相关的信息在join_table显示的是
	#university  device_id  answer_cnt
	#山东大学     5432           3
	#山东大学     2131           1
GROUP BY
    university #2 之后在上面的join_table上进行操作,就是很简单的操作了。你可以试一下北京大学、复旦大学的数据
ORDER BY
    university ASC;

全部评论

相关推荐

2025-12-19 15:04
门头沟学院 Java
小肥罗:hr爱上你了,你负责吗哈哈
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务