题解 | #统计每个学校的答过题的用户的平均答题数#

统计每个学校的答过题的用户的平均答题数

https://www.nowcoder.com/practice/88aa923a9a674253b861a8fa56bac8e5

#  2个表都需要


# select * from user_profile u,question_practice_detail q where u.device_id=q.device_id;
# select university,count(u.device_id) d from user_profile u,question_practice_detail q where u.device_id=q.device_id group by university
select a.university,b.q1/a.d from 
(select university,count(distinct u.device_id) d from user_profile u,question_practice_detail q where u.device_id=q.device_id group by university) a 
,
(select university,count(question_id) q1 from user_profile u,question_practice_detail q where u.device_id=q.device_id group by university) b

where a.university=b.university

先查询总人数(需要去重),在查询总题数

全部评论

相关推荐

LZStarV:冲就好了,就算真的是字节也冲,面评脏了大不了等三四个月就淡了,而且等到那个时候实力进步了选择还多,何必拘泥于字节
点赞 评论 收藏
分享
评论
2
收藏
分享

创作者周榜

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