Top 20 SQL Queries Every Data Analyst Must Know in 2026
The 20 SQL patterns that show up in 80% of data analyst interviews at Google, Amazon, Flipkart and more — explained clearly with real examples.
Every pattern below has appeared in real data analyst interviews in 2025–2026. Learn the pattern, not just the syntax.
1. GROUP BY with HAVING — filter aggregated results
2. INNER JOIN — combine rows from two tables on a key
3. LEFT JOIN — keep all rows from left table, NULLs where no match
4. Subquery in WHERE — filter using a derived result
5. CTE (WITH clause) — readable multi-step queries
6. RANK() / ROW_NUMBER() — rank rows within a partition
7. LAG() / LEAD() — access the previous or next row’s value
8. SUM() OVER() — running total without GROUP BY
9. DATE_TRUNC / DATE_FORMAT — group by week, month, quarter
10. CASE WHEN — conditional columns and category bucketing
11. COALESCE / NULLIF — handle NULL values safely
12. Self JOIN — compare a table to itself (consecutive events, hierarchy)
13. Second highest value without LIMIT — using subquery or DENSE_RANK
14. Rolling N-day average — window frame with ROWS BETWEEN
15. Month-over-month growth — LAG + percentage calculation
16. Retention / Cohort query — self join on user and month offset
17. Deduplicate rows — ROW_NUMBER() = 1 pattern
18. Pivot with CASE WHEN — turn rows into columns
19. Consecutive days / streak detection — date difference = 1 pattern
20. Percentile / median — PERCENTILE_CONT or subquery approach
Want to practise all 20 patterns?
Book a free SQL mock — we’ll run you through 5 real interview questions with live feedback on your approach and syntax.
Book Free SQL Mock