Lesson 10 of 14 · 28 min
Percentiles and distributions
By the end of this lesson you can compute medians and other percentiles with ordered-set aggregates, split rows into equal-sized buckets with NTILE, and express a row's position with PERCENT_RANK and CUME_DIST.
The median is the middle value when the rows are sorted: half are below it and half above. A percentile generalises it: the 90th percentile (p90) is the value below which 90% of the rows fall. The median is p50; the quartiles are p25, p50 and p75.
In Masar Holding's Executive Office, one CEO salary sits next to two much smaller ones; the average lands somewhere no actual employee earns. The median doesn't move when the top salary doubles, which is why HR and compensation teams report medians.
This lesson, its 4 graded exercises and every other Members lesson in SQL Quest come with a Formula Quest membership that includes SQL (Single Quest with SQL selected, Quest Trio including SQL, or Quest Unlimited), or with SQL access from your organization.
Free to everyone: all of SQL Foundations and Retrieving and Filtering Data, the first lesson of every track, the playground, the dataset library and the SQL reference. See free lessons