Editor

Rank the students in each course

Hard · School database · Window functions, JOIN

Rank the students inside each course by marks, highest first. Students with equal marks share a rank and the next rank is skipped, so marks of 95, 95 and 88 rank 1, 1 and 3. Leave out enrollments with no marks.

Return the course name, the student's name, marks and the rank, in that order, sorted by course name, then rank, then student name.

Expected result

coursestudentmarksposition
BiologyFatima Sheikh931
BiologyDiya Menon842
BiologyMeera Patel753
BiologyIshaan Verma744
BiologyKavya Pillai625
ChemistryPriya Nair911
ChemistryAnanya Iyer852
ChemistryMeera Patel683
Computer ScienceVikram Rao981
Computer ScienceYuki Tanaka902
Computer ScienceTanvi Bose873
Computer ScienceLucas Martin664
EconomicsTanvi Bose911
EconomicsDiya Menon802
EconomicsSara Khan733
EnglishAnanya Iyer921
EnglishPriya Nair862
EnglishFatima Sheikh783
EnglishSara Khan783
EnglishKavya Pillai695
Informatics PracticesYuki Tanaka941
Informatics PracticesRahul Das832
Informatics PracticesAditya Joshi773
MathematicsIshaan Verma951
MathematicsVikram Rao951
MathematicsAarav Sharma883
MathematicsArjun Reddy824
MathematicsAditya Joshi715
MathematicsRohan Gupta676
MathematicsKabir Singh587

First 30 of 37 rows.

The school tables

courses: 10 rows, first 5 shown

idnameteacher_idcredits
1Physics14
2Chemistry24
3Mathematics35
4English43
5Biology54

enrollments: 40 rows, first 5 shown

idstudent_idcourse_idmarksenrolled_on
111882025-04-07
213882025-04-07
322912025-04-08
424862025-04-08
531722025-04-09

students: 24 rows, first 5 shown

idnamegenderclasssectioncitydobemail
1Aarav SharmaM12ADelhi2008-05-14aarav.sharma@example.com
2Priya NairF12AKochi2008-09-02priya.nair@example.com
3Rohan GuptaM12BDelhi2008-01-23NULL
4Ananya IyerF12BChennai2008-11-30ananya.iyer@example.com
5Kabir SinghM12CChandigarh2007-12-19kabir.singh@example.com

teachers: 8 rows, first 5 shown

idnamesubjectcityjoined_on
1Sunita MehraPhysicsDelhi2012-06-01
2Rajesh KumarChemistryDelhi2015-07-15
3Lakshmi KrishnanMathematicsChennai2010-04-01
4David ThomasEnglishKochi2018-06-20
5Farah QureshiBiologyMumbai2016-08-01
-- Write your SQL here