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

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

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

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

month(date)=8这一行如果写on后面,因为left join的缘故,当用户没做题的时候也会有一行为空。但是当这一行挪到where后面的时候,不符合条件的会被过滤掉,导致结果为0的一行不显示。

全部评论

相关推荐

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