题意明确:
仅查看山东大学的用户在不同难度下的每个用户的平均答题题目数
问题分解:
- 限定条件:山东大学的用户
up.university="山东大学"
; - 不同难度:按难度分组
group by difficult_level
- 平均答题数:总答题数除以总人数count(qpd.question_id) / count(distinct qpd.device_id) 来自上面信息三个表,需要联表,up与qpd用device_id连接并限定大学,qd与qpd用question_id连接。
细节问题:
- 表头重命名:as
- 平均值精度未明确要求,忽略
完整代码:
|-------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 1 2 3 4 5 6 7 8 9 10 11 12 13 | select up.university, qd.difficult_level, (count(qpd.question_id)/count(distinct qpd.device_id)) 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 up.university,qd.difficult_level having up.university='山东大学' |