SQL
Practice Problem Index
Work these to cement the patterns. Ordered by concept, not difficulty.
Aggregation and GROUP BY
- Count records by status with percent of total
- Multi-metric summary per group with
HAVINGthreshold - Conditional aggregation with
CASE
JOINs
- Multi-table enrichment joins
- Anti-join:
LEFT JOIN ... IS NULLvsNOT EXISTS - Self-join pair problems
Subqueries
- Scalar subquery comparisons against group averages
EXISTSfor multi-condition membershipINandNOT INfiltering cases
CTEs
- Waterfall funnel with counts at each step
- Compute -> classify -> summarize pipelines
- Recursive hierarchy traversal with depth/path
Window Functions
- Latest record per group (
ROW_NUMBER) - Top N per group (
DENSE_RANKorROW_NUMBER) - Running totals
- Month-over-month change with
LAG - Bucketing with
NTILE - Percent of total and cumulative percent
Interview Classics
- Find duplicates
- Nth highest salary
- Consecutive day streaks
- Pivot rows to columns
- Period-over-period growth
- Cohort retention