Blog · Guide
SQL Window Functions: RANK Without Losing Rows
RANK() OVER (ORDER BY …) adds a ranking column while keeping every product row — unlike GROUP BY.
Ranking that keeps detail
SELECT name, price, RANK() OVER (ORDER BY price DESC) AS price_rank FROM products;
You still see each product. GROUP BY would collapse them. Use windows when you need both the row and a running comparison.
PARTITION BY
Want ranks inside each category? RANK() OVER (PARTITION BY category ORDER BY price DESC) restarts the rank per group — practice it on the window partition drill.
Try it yourself
The fastest way to lock this in is a short drill on the same Northstar Market tables.