SQL · Pattern 10 — Window Functions
NTILE()
Divides rows into equal-sized buckets.
Source data — Pattern 10: Window Functions
All queries run against the shared employees table (see schema.sql). This pattern introduces a sales table to demonstrate window functions including ranking, navigation, running totals, moving averages and window aggregates.


What it does
Divides rows into equal-sized buckets.
Problem
Divide employees into four salary groups.
SELECT first_name,salary,
NTILE(4) OVER(ORDER BY salary DESC) AS result
FROM employees;
Result
