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的一行不显示。