SELECT u.device_id, u.university, COALESCE(q.question_cnt, 0) AS question_cnt, COALESCE(q.right_question_cnt, 0) AS right_question_cnt FROM user_profile AS u LEFT OUTER JOIN ( SELECT device_id, SUM( CASE WHEN...