Just added: Embedded C From Zero
PostgreSQL
-- Rank each sale within its region (highest amount = rank 1).
-- GROUP BY would collapse the rows - a window function keeps them.
SELECT rep, region, amount
FROM sales
ORDER BY region, amount DESC;