Menu▾

Topic

Window functions

Ranking, running totals, and comparing a row to its neighbours without collapsing the result set. This is the topic that most often separates a mid-level candidate from a junior one, and PARTITION BY is where it goes wrong.

New to this? Read the Window functions chapter.Prefer a fixed order? Window functions deep-dive.

easyRank grocery items by price within each categoryFree→easyShow each customer's previous purchase amountFree→easyShow every top-up next to the overall averageFree→mediumNumber each subscriber's reloads in orderFree→mediumRunning balance for each e-walletFree→hardBusiest data center in each regionBasic→hardDay-over-day change in order volumeBasic→hardDrivers delayed 3+ days in a rowBasic→hardMonth-over-month change in units soldBasic→hardPrevious month's revenueFree→hardRank customers by spendBasic→hardRank customers by transaction amount, per branchBasic→hardRank projects by margin within each practiceBasic→hardRunning total of daily salesFree→hardSecond most expensive product per categoryFree→hardShow each customer's previous tier alongside their new oneBasic→hardSplit customers into spending quartilesBasic→