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

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

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

select 
    up.device_id,
    up.university,
    count(qpd.question_id) as question_cnt,
    sum(if(qpd.result="right",1,0)) as right_question_cnt
from user_profile as up
left join 
    question_practice_detail as qpd
on up.device_id = qpd.device_id and month(qpd.date)=8
where up.university = '复旦大学'
group by
    up.device_id,
    up.university

# 1.复旦大学

# 2.8月份

# 3.总题目数 count(question_id)

# 4.答题正确的题目数 sum(if(result='right',1,0))

需要注意的细节

1、“对于在8月份没有练习过的用户,答题数结果返回0”,需要将user_profile作为底表,进行左链接 left join

2、对8月进行限制时,需要考虑到,如果month(qpd.date) = 8放在where语句后面,即使是左链接,查询之后返回的结果也是同时满足学校为复旦,且月份为8月的数据,这将会把user_profile表中复旦大学8月没有答题的用户过滤掉

全部评论

相关推荐

04-25 18:13
五邑大学 Java
后来123321:大二两段实习太厉害了,我现在大二连面试都没有
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务