Skip to content

Instantly share code, notes, and snippets.

@tehmoth
Created August 23, 2013 15:24
Show Gist options
  • Save tehmoth/6320577 to your computer and use it in GitHub Desktop.
Save tehmoth/6320577 to your computer and use it in GitHub Desktop.
window version
SELECT name, subject, grade FROM
(SELECT student_id, subject_id, grade, RANK() OVER (PARTITION BY student_id ORDER BY grade)
FROM exams)
AS grades, students, subjects
WHERE grades.subject_id = subjects.subject_id AND grades.student_id = students.student_id
AND rank = 1 ORDER BY grade;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment