Question bank
SQL interview questions
12 SQL interview questions, each with a scenario, an interview-ready answer, a detailed explanation, tested code with real output, production notes and common mistakes.
Window functions
- BeginnerWhat is the difference between ROW_NUMBER, RANK and DENSE_RANK?
- IntermediateHow do you compute a running total and a 7-day moving average?
- AdvancedWhy does LAST_VALUE(salary) OVER (PARTITION BY dept ORDER BY salary) return each row's own salary?
- IntermediateCan you filter on a window function in WHERE?
- IntermediateTop 3 products by revenue per category: ROW_NUMBER, RANK or DENSE_RANK?
- IntermediateHow do you compute month-over-month revenue growth?
Gaps and islands
Deduplication
Ranking
Joins
NULL handling
Query optimisation
Prefer one long read? The SQL Interview Questions guide covers SQL traps topic by topic.