▸_sqlgym

68. Exam Score Percentile

MediumWindow FunctionsCUME_DISTPERCENT_RANKWindow Functions

CUME_DIST() returns the cumulative distribution of a row: the fraction of rows whose ordered value is the current row's value (so the maximum row always gets 1.0). It is a window function, so it runs over an ORDER BY without collapsing rows.

The scores table holds one row per student with an exam score.

Task: for each student, report their percentile as CUME_DIST() over ascending score, expressed as a whole-number percentage rounded to 1 decimal place (multiply by 100, then ROUND(..., 1)).

Return columns student, score, percentile, ordered by score ascending, then student ascending.

Tables
Loading schema…
Expected outputrows must come back in this order
Computing expected output…

This is the result for the example data above. On Submit your query is graded against this example plus 4 hidden edge cases 5test cases in all. A sloppy query that only fits the example won't pass.

SQL
⌘/Ctrl+↵ run · ⇧⌘/Ctrl+↵ submit
Run a query to see its output here.