题解 | 统计每个用户的平均刷题数

统计每个用户的平均刷题数

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

本题的收获:

  1. 如果有group by子句,想在select中查询某个字段,必须要在group子句中加上这个字段
  2. 如果某个字段是唯一的,可以不必加上`table.field`这样的限制,直接写field name就行
全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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