ποΈ SQL
SQL interview questions test fluency with joins, aggregations, and window functions β not arcane DBA trivia. If you can confidently compose
JOIN,GROUP BY,HAVING, and a window function, you can solve 90% of LeetCode SQL.
This category contains 29 problems. Use the patterns below to recognize what's being asked, then jump to the problem list at the bottom.
π§ Key Patternsβ
- Joins (INNER, LEFT, SELF) β Combine rows across tables; SELF JOIN for hierarchies.
- GROUP BY + HAVING β Aggregate then filter on the aggregate.
- Window Functions β
ROW_NUMBER,RANK,DENSE_RANK,LAG,LEAD, running sums. - Subqueries / CTEs β
WITH x AS (...)for readability; correlated subqueries for row-by-row logic. - CASE WHEN β Conditional aggregation, pivots.
- Date Arithmetic β Consecutive dates, gaps & islands β
date - row_numbertrick.