题解 | #统计复旦用户8月练题情况#

统计复旦用户8月练题情况

https://www.nowcoder.com/practice/53235096538a456b9220fce120c062b3

select 
 u.device_id,
 u.university,
 count(q.question_id) as question_cnt,
 sum(case when q.result='right' then 1 else 0 end) as right_question_cnt
# 如果result为right则记为1,其余的无论是wrong还是null全部记为0,然后求和得到的就是正确答题数了
from user_profile u 
left join question_practice_detail q
on u.device_id=q.device_id and month(q.date)=8
# 将表user_profile与question_practice_detail左连接,连接条件为device_id相等且月份为八月
where u.university='复旦大学'
# 学校为复旦大学
group by device_id;
# 按用户分组

全部评论

相关推荐

迷茫的大四🐶:自信一点,我认为你可以拿到50k,低于50k完全配不上你的能力,兄弟,不要被他们骗了,你可以的
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务