解题步骤:
1、将三张表联结成一张表(INNER JOIN);
2、按大学和题目难度分组(GROUP BY);
3、选出大学为山东大学的部分(HAVING,该关键字针对分组进行过滤,WHERE关键字则是对每一条记录过滤);
4、选择要输出的字段(SELECT)。
代码如下:
SELECT university, difficult_level, COUNT(qpd.question_id)/COUNT(DISTINCT up.device_id) AS avg_answer_cnt FROM user_profile AS up INNER JOIN question_practice_detail AS qpd ON up.device_id = qpd.device_id INNER JOIN question_detail as qd ON qpd.question_id = qd.question_id GROUP BY up.university, qd.difficult_level HAVING university='山东大学';