select user_profile.device_id,
       university,
       count(question_practice_detail.device_id) as question_cnt,
       count(IF(result = 'right', 1, null)) right_question_cnt
from user_profile
    left join question_practice_detail
    on question_practice_detail.device_id = user_profile.device_id
where university='复旦大学' and
      (month(date)='08'or
      month(date) is null)
group by user_profile.device_id