判断条件,学校是复旦大学。统计8月和非8月的答题量和正确率,分别对月份和是否正确进行条件判断函数,8月计1,非8月计0,相加。正确计1,非正确计0,相加。按照device_id进行分组统计。
select a.device_id,a.university,sum(case month(date) when 8 then 1 else 0 end) as question_cnt,
sum(case when result ='right' then 1 else 0 end ) as right_question_cnt
from user_profile as a
left join
question_practice_detail as b
on a.device_id=b.device_id
where a.university='复旦大学'
group by a.device_id