Skip to content

Instantly share code, notes, and snippets.

@tehmoth
Created August 23, 2013 15:18

Revisions

  1. tehmoth created this gist Aug 23, 2013.
    5 changes: 5 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    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;