select device_id, university, sum(question), sum(right_question) from ( select a.device_id as device_id, a.university as university, case when question_id is not NULL then 1 when question_id is NULL then 0 end question, result, case when result="right" then 1 else 0 end right_question, dat...