SQL · Pattern 10 — Window Functions
RANK()
Ranks rows with gaps after ties.
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
Ranks rows with gaps after ties.
Problem
Rank employees by sales.
SELECT *,
RANK() OVER(ORDER BY sales_amount DESC) AS result
FROM sales;
Result
