SELECT user_profile.device_id,user_profile.university,IFNULL(B.question,0),IFNULL(B.RIGHT_QUESTION,0) FROM user_profile LEFT JOIN (
SELECT device_id, COUNT(*) AS question,sum((case when result='right' then 1 else 0 end)) as RIGHT_QUESTION
FROM question_practice_detail WHERE month(date)=8 GROUP BY device_id)
AS B ON user_profile.device_id=B.device_id WHERE user_profile.university="复旦大学"