题解 | 统计每个用户的平均刷题数
统计每个用户的平均刷题数
https://www.nowcoder.com/practice/f4714f7529404679b7f8909c96299ac4
select u.university,difficult_level,count(p.question_id)/count(distinct u.device_id) as avg_answer_cnt
from
user_profile u
join
question_practice_detail p on u.device_id = p.device_id
join
question_detail q on p.question_id = q.question_id
where u.university = '山东大学'
group by university,difficult_level
本题的收获:
- 如果有group by子句,想在select中查询某个字段,必须要在group子句中加上这个字段
- 如果某个字段是唯一的,可以不必加上`table.field`这样的限制,直接写field name就行