Quartiles per Class
Hard · Window Functions
NTILE(4) OVER (ORDER BY ...) splits the sorted rows into 4 groups that are as equal in size as possible; when the rows do not divide evenly, the first groups get one extra row. With 9 rows the sizes are 3, 2, 2, 2. With only 3 rows you get groups 1, 2 and 3, and no group 4.
Inside each class, split the students who have a score into quartiles: order them by score descending, then name ascending (so tied scores split deterministically), and use NTILE(4). Quartile 1 holds the best scores. Students with a NULL score are left out.
Return class, quartile, students (how many students are in it), min_score and max_score, sorted by class, then quartile.