Curving Grades 2
You're a backend engineer working on an online education platform similar to Khan Academy, called "Con Academy".
You're still writing the software that grades on a curve that we started in Curving Grades 1.
The grades are in the grades
table, and classes are in the classes
table.
column_name | type | reference |
---|---|---|
id | VARCHAR | NULL |
subject | VARCHAR | NULL |
name | VARCHAR | NULL |
semester | VARCHAR | NULL |
teacher_id | VARCHAR | teachers.id |
column_name | type | reference |
---|---|---|
score | NUMERIC | NULL |
student_id | VARCHAR | students.id |
class_id | VARCHAR | classes.id |
We are using percentiles to assign letter grades based on the following ranges:
Grade | Range |
---|---|
A | 100 - 80% |
B | 80 - 50% |
C | 50 - 25% |
D | 25 - 10% |
F | 10 - 0% |
Now that we know about PARTITION BY
, we can write a comprehensive query.
For all classes, select each student's numerical score
, student_id
, the class name from classes.name
(NOT class_id
),
and letter_grade
based on their percentile within each class.
Order the grades by class name alphabetically, then by highest score.
If 2 students in the same class have the same exact score, order the lower student_id
s first.