📌Why SQL Decides Your Data Analyst Interview
Almost every Data Analyst interview has a SQL round, and it's where most candidates get rejected. The good news: the questions are predictable. Master the patterns below and you'll walk in confident.
These are the real questions asked at companies like Swiggy, Razorpay, Meesho, Amazon, Flipkart and top service companies — grouped from basics to window functions.
📌Basics: Filtering & Sorting
Q1. What is the difference between WHERE and HAVING?
WHERE filters rows before grouping; HAVING filters groups after GROUP BY (and can use aggregate functions).Q2. Difference between DISTINCT and GROUP BY?
Both remove duplicates. GROUP BY is used when you also need aggregations (COUNT, SUM). DISTINCT just returns unique rows.Q3. Find the second-highest salary.
SELECT MAX(salary) AS second_highestFROM employeesWHERE salary < (SELECT MAX(salary) FROM employees);Or, more robustly, with a window function (see Q22).
📌Joins
Q4. Explain INNER, LEFT, RIGHT and FULL JOIN.
Q5. What is a self join? Give a use case.
A table joined to itself — e.g. finding employees and their managers from the sameemployees table.Q6. Customers who never placed an order.
SELECT c.customer_id, c.nameFROM customers cLEFT JOIN orders o ON c.customer_id = o.customer_idWHERE o.order_id IS NULL;📌Aggregations & GROUP BY
Q7. Total revenue per month.
SELECT DATE_TRUNC('month', order_date) AS month, SUM(amount) AS revenueFROM ordersGROUP BY 1ORDER BY 1;Q8. Top 3 products by sales.
SELECT product_id, SUM(amount) AS salesFROM order_itemsGROUP BY product_idORDER BY sales DESCLIMIT 3;Q9. What does COUNT(*) vs COUNT(column) do differently?
COUNT(*) counts all rows; COUNT(column) ignores NULLs in that column.📌Subqueries & CTEs
Q10. What is a CTE and why use it?
A Common Table Expression (WITH) is a named temporary result set that makes complex queries readable and lets you reference it multiple times.Q11. Categories with above-average order value.
WITH cat_avg AS ( SELECT category, AVG(amount) AS avg_amt FROM orders GROUP BY category)SELECT * FROM cat_avgWHERE avg_amt > (SELECT AVG(amount) FROM orders);Q12. Correlated vs non-correlated subquery?
A correlated subquery references the outer query and runs per row; a non-correlated one runs once independently.📌Window Functions (The Difference-Maker)
Q22. Second-highest salary per department.
SELECT department, salaryFROM ( SELECT department, salary, DENSE_RANK() OVER (PARTITION BY department ORDER BY salary DESC) AS rnk FROM employees) tWHERE rnk = 2;Q23. Difference between ROW_NUMBER, RANK and DENSE_RANK?
Q24. Running total of daily sales.
SELECT order_date, SUM(amount) OVER (ORDER BY order_date) AS running_totalFROM daily_sales;Q25. Month-over-month growth with LAG.
SELECT month, revenue, revenue - LAG(revenue) OVER (ORDER BY month) AS mom_changeFROM monthly_revenue;📌How to Prepare (and Actually Pass)
Reading answers isn't enough — you must write queries by hand. Practice on real schemas, explain your logic out loud, and rebuild each pattern from scratch. Analytical questions (cohorts, funnels, retention) increasingly use window functions, so get very comfortable with them.
Our SQL for Data Analytics course drills exactly these patterns with real analytical case studies and mock interviews. For the complete analyst skill set — SQL plus Excel, statistics, Power BI and Tableau — see the Data Analytics course.
Master these 30 patterns and the SQL round becomes the easiest part of your interview.