Skip to content

Instantly share code, notes, and snippets.

@tehmoth
Created August 23, 2013 15:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tehmoth/6320512 to your computer and use it in GitHub Desktop.
Save tehmoth/6320512 to your computer and use it in GitHub Desktop.
WINDOW version
SELECT name, subject, grade FROM
(SELECT students.name, subjects.subject, grade, RANK() over (PARTITION BY students.student_id ORDER BY grade) rank
FROM exams, students, subjects
WHERE exams.subject_id = subjects.subject_id AND exams.student_id = students.student_id) AS grades
WHERE rank = 1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment