Skip to content

Instantly share code, notes, and snippets.

@shunjikonishi
Created July 1, 2015 06:10
Show Gist options
  • Save shunjikonishi/20d78dc4a57a422a9215 to your computer and use it in GitHub Desktop.
Save shunjikonishi/20d78dc4a57a422a9215 to your computer and use it in GitHub Desktop.
SELECT
c.id,
count(cr.id) as count
FROM challenges c
LEFT OUTER JOIN exam_challenges ec ON (c.id = ec.challenge_id)
INNER JOIN exams e ON (ec.exam_id = e.id)
LEFT OUTER JOIN exam_delivers ed ON (ed.exam_id = e.id)
LEFT OUTER JOIN challenge_results cr ON (c.id = cr.challenge_id AND cr.deliver_id = ed.id)
WHERE c.user_id in (1)
GROUP BY c.id
ORDER BY c.id desc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment