SQL Interview Questions for Data Analysts — 50 Practice Problems
20 fully solved problems (Easy → Hard) plus a catalogue of 30 more — JOINs, GROUP BY, window functions, CTEs, de-duplication, cohort retention, consecutive events, and pivot queries. Every solution includes what the interviewer is testing. Indian e-commerce context throughout.
30 More Questions to Practice (Titles + Topics)
Frequently Asked Questions
What SQL topics are tested in Indian data analyst interviews?
Based on patterns from Indian companies in 2026, the most frequently tested SQL topics for data analyst roles are: (1) JOINs — INNER, LEFT, and anti-joins using LEFT JOIN ... WHERE IS NULL. Almost every interview has at least one JOIN question. (2) GROUP BY and HAVING — aggregate functions (SUM, COUNT, AVG, MAX, MIN) with GROUP BY, and filtering aggregates with HAVING. (3) Window functions — RANK, DENSE_RANK, ROW_NUMBER for top-N-per-group problems; LAG/LEAD for period-over-period comparisons; running totals with SUM() OVER. (4) Subqueries and CTEs — especially multi-step business logic that requires intermediate aggregations. (5) NULL handling — COALESCE, NULLIF, IS NULL vs = NULL distinction. (6) Date functions — DATEDIFF, DATE_FORMAT, YEAR/MONTH/DAY extraction, period-over-period date arithmetic. (7) De-duplication — keeping the latest record per entity using ROW_NUMBER or MAX aggregation. The difficulty distribution is typically: 40% easy (basic SELECT/WHERE/GROUP BY), 40% medium (JOINs, subqueries, NULLs, date logic), 20% hard (window functions, CTEs, optimisation).
How do you prepare for a SQL interview in 2 weeks?
A structured 2-week SQL interview preparation plan: Week 1 — Solidify fundamentals. Day 1–2: SELECT, WHERE, ORDER BY, LIMIT. Day 3–4: GROUP BY, HAVING, aggregate functions (COUNT, SUM, AVG, MIN, MAX). Day 5–6: JOINs (INNER, LEFT, RIGHT, anti-join pattern). Day 7: NULL handling, COALESCE, CASE WHEN, date functions. Week 2 — Advanced and practice. Day 8–9: Subqueries (scalar, correlated, EXISTS). Day 10–11: Window functions (RANK, ROW_NUMBER, LAG, running totals). Day 12: CTEs and multi-step analysis. Day 13: Practice 10 medium-level questions timed (15 minutes each). Day 14: Review mistakes, practise explaining your solutions out loud. Key resources: LeetCode SQL (easy and medium), HackerRank SQL track, Mode Analytics SQL tutorial. For Indian context: practise on e-commerce and fintech scenarios (orders, customers, payments) rather than abstract problems. Be able to explain your solution in plain English — interviewers test understanding, not just correct syntax.
What is the hardest SQL concept tested in analyst interviews in India?
Window functions are consistently the hardest concept tested, specifically: (1) Top-N per group using ROW_NUMBER() OVER (PARTITION BY category ORDER BY sales DESC) — then filtering with WHERE rn = 1 in an outer query. Many candidates write GROUP BY solutions that do not handle ties correctly. (2) Consecutive events — find customers who placed orders on 3 or more consecutive days. This requires LAG() with date arithmetic and a self-join or gaps-and-islands technique. (3) Running totals and period averages — "calculate a 7-day rolling average of daily orders" requires AVG() OVER with ROWS BETWEEN 6 PRECEDING AND CURRENT ROW. (4) Cohort retention — what percentage of January customers placed a second order in February? This requires self-joining the orders table on customer_id with different date filters, which many candidates overcomplicate. The most common mistake is trying to solve window function problems with subqueries or multiple passes — window functions almost always produce cleaner, faster solutions.
EVIKA ACADEMY · NOIDA SECTOR 51
Crack Your SQL Interview
Our SQL interview preparation module covers 100+ practice problems on real Indian business datasets, with mock interview sessions and feedback from experienced data professionals.
Book Free Demo Class →