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

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

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

首先 找到两个表的联系,得知是 device_id 用左连接 
这里得分两种case:
1、空的 ()
2、包括8月 (说明:8月可能有练习的,也有没有练习的)
然后利用where 将两种情况分开

#case1:
select p1.device_id,p1.university,count(date) as question_cnt,
sum(if(p2.result="wrong",0,1)) as right_question_cnt
 from user_profile as p1 left join question_practice_detail  as p2
on p1.device_id=p2.device_id
where  p1.university="复旦大学" and date is not null and month(date)=8
group by p1.device_id

union
#case2
select p1.device_id,p1.university,count(date) as question_cnt,
sum(if(p2.result is null,0,0)) as right_question_cnt
 from user_profile as p1 left join question_practice_detail  as p2
on p1.device_id=p2.device_id
where  p1.university="复旦大学" and date is  null
group by p1.device_id



全部评论

相关推荐

找个工作 学历是要卡的 要求是高的 技能不足是真的 实习经验是0的 简历无处可写是事实的 钱不好赚是真的 想躺平又不敢躺 也不甘心躺 怕自己的灵感和才华被掩埋甚至从未被自己发现 又质疑自己是否真正有才华
码农索隆:你现在啊,你心里都明白咋回事,但是你没办法改变现状,一想到未来,你又没有信心狠下心来在当下努力。 得走出这种状态,不能一直困在那里面,哪不行就去提升哪,你一动不动那指定改变不了未来,动起来,积少成多才能越来越好
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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