Where Does Each Order Rank? (PERCENT_RANK, CUME_DIST)

medium
Checkpoint challenge
Solve this to show you know the material and jump straight to Unit 13. Everything before it counts as cleared.

For each order, return id, total, pct_rank and cume_dist, both computed over all orders ordered by total and rounded to 2 decimal places. Sort by total, then id.

  • PERCENT_RANK() is (rank - 1) / (rows - 1): 0 for the smallest, 1 for the largest.
  • CUME_DIST() is the fraction of rows with a value less than or equal to the current one.

Schema

customers(id, name, country, signup_date)
orders(id, customer_id, order_date, total)
#window-functions#percentiles1 visible + 1 hidden tests
query.sql · SQLite
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Where Does Each Order Rank? (PERCENT_RANK, CUME_DIST) · TechGradify