LEFT JOIN class_member_mapping cm ON cm.member_id = m.id
LEFT JOIN class_member_mapping cm ON cm.member_id = m.id
LEFT JOIN ( SELECT member_id, count( 1 ) AS ts FROM exercise_done_result WHERE score >= 60 GROUP BY class_id ) AS r ON r.member_id = m.id
LEFT JOIN ( SELECT member_id, count( 1 ) AS ts, class_id FROM exercise_done_result WHERE score >= 60 GROUP BY class_id ) AS r ON r.member_id = m.id AND r.class_id = cm.class_id