题解 | #统计复旦用户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 university='复旦大学' 
group by device_id

注意

  1. 左连接时候,不能写成select qpd.device_id,否则将device_id=4321的用户的device_id将被识别为None
  2. on和where的区别,如果写成
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 
where university='复旦大学' and month(qpd.date)=8
group by device_id

即将and放在where后面,将不能识别出4321那个用户。

全部评论
大佬能不能帮忙解释下 为什么and放在where后面,将不能识别出4321那个用户?
点赞 回复 分享
发布于 03-15 00:37 上海
大佬解答了我的疑惑,感恩!
点赞 回复 分享
发布于 2023-04-13 15:56 湖南

相关推荐

点赞 评论 收藏
分享
评论
7
5
分享

创作者周榜

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