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

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

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

select u.device_id,u.university,count(q.question_id) 'question_cnt', 
sum(case when q.result='right' then 1 else 0 end) 'right_question_cnt'
from user_profile u left join question_practice_detail q
on u.device_id=q.device_id and q.date like '%-08-%'
where u.university='复旦大学'
group by u.device_id;

根据题干,要求没有数据显示0,可知需要使用外连接

两个问题:1、没有看到题干要求8月份

2、看到8月后,将q.date like '%-08-%'加在where条件里面,这样就失去左外连接的作用了,放在on里面就可以保留左表的数据

全部评论

相关推荐

评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务