SQL interview prep, explained
The patterns behind the questions in the bank — window functions, joins, the traps that fail candidates — each one linking into a graded question to try it yourself.
- How to find the second-highest value per group in SQL
The runner-up-per-category question shows up under a dozen names in interviews. Here is the ROW_NUMBER pattern, why WHERE can't filter a window function directly, and what changes when values tie.
5 min read
- Running totals in SQL: SUM() OVER, and the frame clause that trips people up
A cumulative sum looks like a one-liner until the default window frame gives a wrong answer for a tied row. Here is the correct pattern and the frame clause that actually controls it.
4 min read
- Month-over-month growth in SQL with LAG() — and why a self-join is the wrong tool
Comparing each row to the previous one is a self-join in most people's first instinct and a one-line LAG() in the right one. Here is why, plus the NULL-first-row and gap-month edge cases interviewers actually probe.
5 min read