Career Guide

Top 20 SQL Interview Questions for Data Analyst Roles in India (2026)

SQL is the #1 skill tested in data analyst interviews across India. Here are the 20 most commonly asked SQL questions with clear explanations and real query examples.

Walk into any data analyst interview in India — at Flipkart, Swiggy, Juspay, Meesho, or a Series B startup — and you will almost certainly be asked to write SQL on a whiteboard or shared editor. It is not optional. It is the gatekeeper skill.

Here are the 20 most important SQL questions with real queries you can study and practice right now.


Foundational Queries

1. Retrieve all employees with a salary greater than ₹80,000

SELECT employee_id, name, salary
FROM employees
WHERE salary > 80000
ORDER BY salary DESC;

2. Find the total orders placed per customer

SELECT customer_id, COUNT(order_id) AS total_orders
FROM orders
GROUP BY customer_id
ORDER BY total_orders DESC;

3. Filter groups using HAVING (customers with more than 5 orders)

SELECT customer_id, COUNT(order_id) AS total_orders
FROM orders
GROUP BY customer_id
HAVING COUNT(order_id) > 5;

Interview tip: Know the difference — WHERE filters rows before grouping; HAVING filters groups after aggregation.


JOINs (The Most Tested Topic)

4. INNER JOIN — Get order details with customer names

SELECT c.name, o.order_id, o.order_date, o.amount
FROM customers c
INNER JOIN orders o ON c.customer_id = o.customer_id;

5. LEFT JOIN — Show all customers even if they have no orders

SELECT c.name, o.order_id
FROM customers c
LEFT JOIN orders o ON c.customer_id = o.customer_id;

6. Find customers who have NEVER placed an order

SELECT c.name
FROM customers c
LEFT JOIN orders o ON c.customer_id = o.customer_id
WHERE o.order_id IS NULL;

This is a classic interview question. The trick is the IS NULL check on the right-side join column.


Subqueries

7. Find employees earning above the average salary

SELECT name, salary
FROM employees
WHERE salary > (SELECT AVG(salary) FROM employees);

8. Find the second highest salary

SELECT MAX(salary) AS second_highest
FROM employees
WHERE salary < (SELECT MAX(salary) FROM employees);

This is one of the most frequently asked SQL questions in Indian interviews. Know it cold.


Window Functions (Advanced but Heavily Tested)

9. ROW_NUMBER — Rank employees within each department by salary

SELECT name, department, salary,
       ROW_NUMBER() OVER (PARTITION BY department ORDER BY salary DESC) AS row_num
FROM employees;

10. RANK vs DENSE_RANK

SELECT name, salary,
       RANK() OVER (ORDER BY salary DESC) AS rnk,
       DENSE_RANK() OVER (ORDER BY salary DESC) AS dense_rnk
FROM employees;

Key difference: RANK() leaves gaps after ties (1, 2, 2, 4). DENSE_RANK() does not (1, 2, 2, 3).

11. Top 3 earners per department (a very common DA question)

SELECT * FROM (
  SELECT name, department, salary,
         DENSE_RANK() OVER (PARTITION BY department ORDER BY salary DESC) AS dr
  FROM employees
) ranked
WHERE dr <= 3;

12. LAG — Compare each day's revenue with the previous day

SELECT order_date,
       SUM(amount) AS daily_revenue,
       LAG(SUM(amount)) OVER (ORDER BY order_date) AS prev_day_revenue
FROM orders
GROUP BY order_date;

13. LEAD — Show the next day's revenue alongside today's

SELECT order_date,
       SUM(amount) AS daily_revenue,
       LEAD(SUM(amount)) OVER (ORDER BY order_date) AS next_day_revenue
FROM orders
GROUP BY order_date;

Companies like Swiggy and Flipkart use LAG/LEAD constantly for day-over-day growth analysis.


NULL Handling

14. Find all records where the email field is NULL

SELECT * FROM users WHERE email IS NULL;

15. Replace NULL values with a default using COALESCE

SELECT name, COALESCE(phone, 'Not Provided') AS phone
FROM users;

CTEs (Common Table Expressions)

16. Use a CTE to find high-value customers (orders > ₹10,000 total)

WITH high_value AS (
  SELECT customer_id, SUM(amount) AS total_spent
  FROM orders
  GROUP BY customer_id
  HAVING SUM(amount) > 10000
)
SELECT c.name, hv.total_spent
FROM customers c
JOIN high_value hv ON c.customer_id = hv.customer_id;

CTEs make complex queries readable. In interviews, using a CTE instead of a nested subquery signals seniority.


Aggregations and Date Functions

17. Monthly revenue trend

SELECT DATE_FORMAT(order_date, '%Y-%m') AS month,
       SUM(amount) AS monthly_revenue
FROM orders
GROUP BY DATE_FORMAT(order_date, '%Y-%m')
ORDER BY month;

18. Find duplicate rows in a table

SELECT email, COUNT(*) AS count
FROM users
GROUP BY email
HAVING COUNT(*) > 1;

19. Delete duplicate rows keeping only one

DELETE FROM users
WHERE id NOT IN (
  SELECT MIN(id)
  FROM users
  GROUP BY email
);

20. Running total of revenue

SELECT order_date, amount,
       SUM(amount) OVER (ORDER BY order_date) AS running_total
FROM orders;

Interview Tips for Data Analyst SQL Rounds in India

  • At Juspay and Razorpay: Expect payment funnel analysis queries — conversion rates, drop-off analysis, cohort retention.
  • At Swiggy and Zomato: Delivery time analysis, restaurant order patterns, geographic aggregations.
  • At Flipkart: Product performance, GMV analysis, return rate queries.

Always ask clarifying questions before writing your query: "Should I include NULL values?" "Is this across all time periods or a specific date range?" Thinking out loud is rewarded.

Practice on Mode Analytics SQL Tutorial, LeetCode SQL problems (Medium and Hard), and HackerRank SQL challenges. The gap between knowing SQL and being interview-ready is about 50–60 hours of deliberate practice.

📢 Share this article