题解 | #统计复旦用户8月练题情况# CASE表达式

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

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

select u1.device_id, university, sum(case when month(date)=8 then 1 else 0 end) question_cnt, sum(case when result ='right' then 1 else 0 end) right_question_cnt
from  user_profile u1 left join question_practice_detail qpd on qpd.device_id = u1.device_id
where university = '复旦大学'
group by u1.device_id;

不能以qpd表为基础使用join,因为没有答题的人的id在里面显示不出来;(inner) join也不可以,因为未答题的id不被视作两个表中重合的数据,因此需要使用left join

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务