Percent Rank of Each Order

medium
Unit 15 · Window Functions VIII0/2 to milestone

Return every order's id, total and pct_rank: its PERCENT_RANK() by total ascending, rounded to 3 decimals. Sort by total, then id.

PERCENT_RANK is (rank - 1) / (rows - 1), so the smallest order gets 0 and the largest gets 1.

Schema

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