Ctr

Curving Grades 1

You're a backend engineer working on an online education platform similar to Khan Academy, called "Con Academy". Your assignment is to write the software that assigns letter grades based on the students' numerical scores in their class. The grades are in the grades table, and classes are in the classes table.


classes
column_name type reference
id
VARCHAR
NULL
subject
VARCHAR
NULL
name
VARCHAR
NULL
semester
VARCHAR
NULL
teacher_id
VARCHAR
teachers.id

grades
column_name type reference
score
NUMERIC
NULL
student_id
VARCHAR
students.id
class_id
VARCHAR
classes.id

The classes vary in difficulty, and some have much lower average scores. However, you want to make sure the letter grades have the same distribution for each class regardless of difficulty. Therefore, you need to grade on a curve.

Curve grading will be done based on percentiles. The percentile for a student's score is the percentage of students that have a score less than or equal to that score. Therefore, if the highest scoring student gets a 98.90, then the percentile for 98.90 is by definition 100%. Letter grades will be assigned according to the following percentile ranges:

Grade Range
A 100 - 80%
B 80 - 50%
C 50 - 25%
D 25 - 10%
F 10 - 0%

The bottom of each range is non-inclusive. That means 80% gets a B, not an A.

For now, you're just testing this on the 2021 2nd semester session of "Cell Biology", a particularly difficult class on Con Academy. Limit the letter grade assignments to only the students in that class. Select each student's numerical score, student_id, class_id, and letter grade (alias it letter_grade). Order the result with the highest score first.

You might want to look into the cume_dist() function.

© 2022 Andrew Carlson. All rights reserved.

score
NUMERIC
student_id
VARCHAR
class_id
VARCHAR
letter_grade
TEXT
1
74.24
75936043
893899942
A
2
66.74
55106019
893899942
A
3
59.71
15047676
893899942
A
4
57.36
91755983
893899942
B
5
52.06
88267756
893899942
B
6
43.83
43578854
893899942
B
7
38.92
73923751
893899942
C
8
35.75
63317043
893899942
C
9
33.8
17286425
893899942
C
10
33.48
74916258
893899942
D
11
28.5
84705733
893899942
D
12
12.82
91867583
893899942
F
12 rows

You haven't solved this challenge yet!
Are you sure you want to reveal the answer?