解题

类似SQL 入门 23,但是加限制为山东大学,

可在GROUP BY前加WHERE实现
或在GROUP BY后加HAVING实现【同时GROUP BY需要增加university】

题解

题目:运营想要仅查看山东大学的用户在不同难度下的每个用户的平均答题题目数情况,请取出相应数据
WHERE实现

SELECT university,difficult_level,COUNT(qpd.device_id) / COUNT(DISTINCT qpd.device_id)
AS avg_answer_cnt
FROM user_profile up
JOIN question_practice_detail qpd ON up.device_id = qpd.device_id
JOIN question_detail qd ON qpd.question_id = qd.question_id
WHERE university='山东大学'
GROUP BY difficult_level

或者HAVING实现

SELECT university,difficult_level,COUNT(qpd.device_id) / COUNT(DISTINCT qpd.device_id)
AS avg_answer_cnt
FROM user_profile up 
JOIN question_practice_detail qpd ON up.device_id = qpd.device_id
JOIN question_detail qd ON qpd.question_id = qd.question_id
GROUP BY university,difficult_level
HAVING university='山东大学'

示例:user_profile

示例:question_practice_detail

示例:question_detail

根据示例,你的查询应返回以下结果: