


先介绍 If 函数:

思路:
①先用1表left join 2表并筛选出8月份数据
②对8月份数据的处理使用on,因为我们要在原表中保留null(where是删除)
③筛选出复旦大学的数据
select
t1.device_id,
t1.university,
count(t2.device_id) as question_cnt,
sum(if(t2.result='right',1,0)) as right_question_cnt
from
user_profile t1
left join
question_practice_detail t2
on t1.device_id=t2.device_id and month(t2.date)=8
where t1.university='复旦大学'
group by t1.device_id,t1.university
3196

被折叠的 条评论
为什么被折叠?



