select a.device_id,
       university, 
       sum(case 
           when month(date)='08' then 1 
           when month(date) is null then 0 end) question_cnt,
       sum(if(result = 'right' ,1,0)) right_question_cnt
from question_practice_detail a
left join user_profile b
on a.device_id = b.device_id
where university = '复旦大学'