SQL is the single most tested skill in every data analyst interview in India — bar none. Whether you are interviewing at Amazon, Flipkart, TCS, HDFC, Swiggy, or a Series B startup, you will face at least 5–10 SQL interview questions for data analyst India 2026 in some form. The good news is that the same core patterns come up again and again across every company and every industry.
This guide covers the 30 most important SQL interview questions for data analysts in India in 2026—with complete, production-quality solutions and explanations that tell you not just what the answer is, but why it works and how to explain it confidently in an interview room.
Why SQL Remains the Most Important Skill for Data Analysts in India 2026
Despite the rise of Python, Power BI, and no-code tools, SQL interview questions for data analysts in India in 2026 remain the centerpiece of every technical screening round. Here is why:
- Over 90% of company data lives in relational databases (MySQL, PostgreSQL, BigQuery, Redshift)
- SQL is the lingua franca of data teams—analysts, engineers, and product managers all use it
- A good SQL query is faster and more scalable than Python for most data extraction tasks
- Interviewers can quickly test logical thinking, problem decomposition, and attention to detail through SQL interview questions for data analysts in India 2026
The 30 questions below are organized from foundational to advanced, matching the progression you will encounter across interview rounds.
Foundational SQL Questions (Rounds 1 and Online Assessments)
Q1. Retrieve all customers who placed an order in the last 30 days.
sql
SELECT DISTINCT customer_id
FROM orders
WHERE order_date >= CURDATE() - INTERVAL 30 DAY;
Why it matters: Date filtering is one of the most fundamental SQL interview questions for data analysts in India in 2026. Use CURDATE() in MySQL or CURRENT_DATE in PostgreSQL.
Q2. Find the total revenue generated by each product category.
sql
SELECT
category,
SUM(revenue) AS total_revenue
FROM products p
JOIN order_items oi ON p.product_id = oi.product_id
GROUP BY category
ORDER BY total_revenue DESC;
Why it matters: GROUP BY with aggregation is tested in virtually every set of SQL interview questions for data analyst India 2026 and represents the most common real-world reporting pattern.
Q3. Find all customers who have never placed an order.
sql
SELECT c.customer_id, c.name
FROM customers c
LEFT JOIN orders o ON c.customer_id = o.customer_id
WHERE o.customer_id IS NULL;
Why it matters: The LEFT JOIN + IS NULL pattern for finding non-matching records is a classic and frequently tested SQL interview question for data analysts in India in 2026 and a technique at companies like Flipkart and Swiggy.
Q4. Get the second-highest salary from an employee table.
sql
-- Method 1: Using subquery
SELECT MAX(salary) AS second_highest
FROM employees
WHERE salary < (SELECT MAX(salary) FROM employees);
-- Method 2: Using LIMIT and OFFSET (MySQL)
SELECT salary
FROM employees
ORDER BY salary DESC
LIMIT 1 OFFSET 1;
Why it matters: This is one of the most universally asked SQL interview questions for data analysts in India in 2026 across all company types—from TCS and Infosys to Amazon and Flipkart.
Q5. Write a query to find duplicate email addresses in a users table.
sql
SELECT email, COUNT(*) AS count
FROM users
GROUP BY email
HAVING COUNT(*) > 1;
Why it matters: Data quality and deduplication problems are a daily reality for analysts, making this a natural SQL interview questions for data analyst India 2026 topic across all rounds.
Q6. Calculate the percentage of total sales each product contributes.
sql
SELECT
product_name,
SUM(sales) AS product_sales,
ROUND(SUM(sales) * 100.0 / SUM(SUM(sales)) OVER (), 2) AS pct_of_total
FROM sales_data
GROUP BY product_name
ORDER BY product_sales DESC;
Why it matters: The window function within an aggregate is a powerful pattern that separates strong candidates in SQL interview questions for data analyst India 2026 advanced rounds.
Intermediate SQL Questions (Technical Rounds 2 and 3)
Q7. Rank customers by total order value within each city.
sql
SELECT
customer_id,
city,
SUM(order_value) AS total_value,
RANK() OVER (PARTITION BY city ORDER BY SUM(order_value) DESC) AS city_rank
FROM orders
JOIN customers USING (customer_id)
GROUP BY customer_id, city;
Why it matters: PARTITION BY window functions are among the most important SQL interview questions for data analysts in India in 2026 for product analytics roles at companies like Amazon India and Meesho.
Q8. Find the top 3 selling products in each category.
sql
WITH ranked_products AS (
SELECT
category,
product_name,
SUM(quantity_sold) AS total_sold,
RANK() OVER (PARTITION BY category ORDER BY SUM(quantity_sold) DESC) AS rnk
FROM sales
JOIN products USING (product_id)
GROUP BY category, product_name
)
SELECT category, product_name, total_sold
FROM ranked_products
WHERE rnk <= 3;
Why it matters: CTEs combined with window functions represent the gold standard solution pattern for SQL interview questions for data analysts in India in 2026 at product analytics companies.
Q9. Calculate the 7-day rolling average of daily orders.
sql
SELECT
order_date,
COUNT(*) AS daily_orders,
AVG(COUNT(*)) OVER (
ORDER BY order_date
ROWS BETWEEN 6 PRECEDING AND CURRENT ROW
) AS rolling_7day_avg
FROM orders
GROUP BY order_date
ORDER BY order_date;
Why it matters: Rolling averages are a staple business metric that appears in almost every set of SQL interview questions for data analyst India 2026 at data-heavy companies.
Q10. Find customers who placed orders in both January and February 2026.
sql
SELECT customer_id
FROM orders
WHERE MONTH(order_date) = 1 AND YEAR(order_date) = 2026
INTERSECT
SELECT customer_id
FROM orders
WHERE MONTH(order_date) = 2 AND YEAR(order_date) = 2026;
Alternative using GROUP BY:
sql
SELECT customer_id
FROM orders
WHERE order_date BETWEEN '2026-01-01' AND '2026-02-28'
GROUP BY customer_id
HAVING COUNT(DISTINCT MONTH(order_date)) = 2;
Q11. Write a query to find month-over-month revenue growth.
sql
WITH monthly_revenue AS (
SELECT
DATE_FORMAT(order_date, '%Y-%m') AS month,
SUM(revenue) AS total_revenue
FROM orders
GROUP BY month
)
SELECT
month,
total_revenue,
LAG(total_revenue) OVER (ORDER BY month) AS prev_month_revenue,
ROUND(
(total_revenue - LAG(total_revenue) OVER (ORDER BY month))
* 100.0 / LAG(total_revenue) OVER (ORDER BY month),
2
) AS mom_growth_pct
FROM monthly_revenue;
Why it matters: MoM growth using LAG() is one of the most business-critical and commonly tested SQL interview questions for data analysts in India in 2026 at growth-oriented companies.
Q12. Find users who have not been active for more than 90 days.
sql
SELECT user_id, MAX(activity_date) AS last_active
FROM user_activity
GROUP BY user_id
HAVING MAX(activity_date) < CURDATE() - INTERVAL 90 DAY;
Q13. Write a query to pivot monthly sales data from rows to columns.
sql
SELECT
product_id,
SUM(CASE WHEN MONTH(sale_date) = 1 THEN amount ELSE 0 END) AS Jan,
SUM(CASE WHEN MONTH(sale_date) = 2 THEN amount ELSE 0 END) AS Feb,
SUM(CASE WHEN MONTH(sale_date) = 3 THEN amount ELSE 0 END) AS Mar
FROM sales
WHERE YEAR(sale_date) = 2026
GROUP BY product_id;
Why it matters: CASE WHEN pivoting is a classic and almost universal SQL interview question for data analysts in India in 2026—every analyst uses it for custom report creation.
Q14. Find the average time between a user’s first and second orders.
sql
WITH order_sequence AS (
SELECT
customer_id,
order_date,
ROW_NUMBER() OVER (PARTITION BY customer_id ORDER BY order_date) AS order_num
FROM orders
)
SELECT
AVG(DATEDIFF(o2.order_date, o1.order_date)) AS avg_days_between_orders
FROM order_sequence o1
JOIN order_sequence o2
ON o1.customer_id = o2.customer_id
AND o1.order_num = 1
AND o2.order_num = 2;
Q15. Write a query to find the most recent transaction for each customer.
sql
SELECT *
FROM transactions t
WHERE transaction_date = (
SELECT MAX(transaction_date)
FROM transactions
WHERE customer_id = t.customer_id
);
Alternative with a window function:
sql
SELECT * FROM (
SELECT *,
ROW_NUMBER() OVER (PARTITION BY customer_id ORDER BY transaction_date DESC) AS rn
FROM transactions
) ranked
WHERE rn = 1;
Advanced SQL Questions (Senior Analyst and Final Rounds)
Q16. Build a cohort retention table — what percentage of users acquired each month are still active in subsequent months?
sql
WITH cohort AS (
SELECT
user_id,
DATE_FORMAT(MIN(activity_date), '%Y-%m') AS cohort_month
FROM user_activity
GROUP BY user_id
),
monthly_activity AS (
SELECT
ua.user_id,
c.cohort_month,
DATE_FORMAT(ua.activity_date, '%Y-%m') AS activity_month,
PERIOD_DIFF(
DATE_FORMAT(ua.activity_date, '%Y%m'),
DATE_FORMAT(c.cohort_month, '%Y%m')
) AS months_since_cohort
FROM user_activity ua
JOIN cohort c ON ua.user_id = c.user_id
)
SELECT
cohort_month,
months_since_cohort,
COUNT(DISTINCT user_id) AS active_users
FROM monthly_activity
GROUP BY cohort_month, months_since_cohort
ORDER BY cohort_month, months_since_cohort;
Why it matters: Cohort analysis is the gold standard product analytics tool and one of the most impressive answers you can give in advanced SQL interview questions for data analyst India 2026 rounds.
Q17. Write a recursive CTE to find all employees in a manager’s hierarchy.
sql
WITH RECURSIVE employee_hierarchy AS (
-- Anchor: start with the top manager
SELECT employee_id, name, manager_id, 0 AS level
FROM employees
WHERE manager_id IS NULL
UNION ALL
-- Recursive: find reports of each employee
SELECT e.employee_id, e.name, e.manager_id, eh.level + 1
FROM employees e
JOIN employee_hierarchy eh ON e.manager_id = eh.employee_id
)
SELECT * FROM employee_hierarchy ORDER BY level;
Q18. Find sessions where a user viewed more than 3 pages within 30 minutes.
sql
WITH session_data AS (
SELECT
user_id,
page_view_time,
LAG(page_view_time) OVER (PARTITION BY user_id ORDER BY page_view_time) AS prev_view_time
FROM page_views
)
SELECT user_id, COUNT(*) AS views_in_session
FROM session_data
WHERE TIMESTAMPDIFF(MINUTE, prev_view_time, page_view_time) <= 30
OR prev_view_time IS NULL
GROUP BY user_id
HAVING COUNT(*) > 3;
Q19. Calculate customer Lifetime Value (LTV) grouped by acquisition channel.
sql
SELECT
acquisition_channel,
COUNT(DISTINCT customer_id) AS customers,
SUM(order_value) AS total_revenue,
ROUND(SUM(order_value) / COUNT(DISTINCT customer_id), 2) AS avg_ltv
FROM orders
JOIN customers USING (customer_id)
GROUP BY acquisition_channel
ORDER BY avg_ltv DESC;
Q20. Write a query to detect fraudulent transactions—flag any transaction that is more than 3 standard deviations above the customer’s average.
sql
WITH customer_stats AS (
SELECT
customer_id,
AVG(amount) AS avg_amount,
STDDEV(amount) AS std_amount
FROM transactions
GROUP BY customer_id
)
SELECT t.*,
cs.avg_amount,
cs.std_amount,
'FRAUD_RISK' AS flag
FROM transactions t
JOIN customer_stats cs ON t.customer_id = cs.customer_id
WHERE t.amount > cs.avg_amount + (3 * cs.std_amount);
Why it matters: Fraud detection using statistical thresholds in SQL is a highly valued and increasingly common pattern in SQL interview questions for data analysts in India 2026 at BFSI and fintech companies like PhonePe, Razorpay, and HDFC analytics teams.
10 Quick-Fire SQL Questions You Must Know Cold
These shorter SQL interview questions for data analysts in India in 2026 are asked in warm-up rounds or online assessments:
Q21. Difference between UNION UNION and UNION ALL? → UNION removes duplicates; UNION ALL keeps all rows, including duplicates. UNION ALL is faster.
Q22. What is a CTE (Common Table Expression)? → A temporary named result set defined with WITH. Improves readability and can be referenced multiple times in the same query.
Q23. What is the difference between DELETE, and DROP? → DELETE removes specific rows (can be rolled back). TRUNCATE removes all rows fast (cannot be rolled back in most DBs). DROP removes the entire table structure.
Q24. What is an index, and when should you use one? → An index speeds up SELECT queries on large tables by creating a lookup structure. Use on columns frequently used in WHERE, JOIN, or ORDER BY clauses. Avoid over-indexing, as it slows INSERT/UPDATE operations.
Q25. What is the difference between RANK(), and ROW_NUMBER()? → RANK() skips numbers after ties (1, 1, 3). DENSE_RANK() does not skip (1, 1, 2). ROW_NUMBER() always assigns unique sequential numbers regardless of ties.
Q26. How do you find the Nth highest value without using the LIMIT clause? → Use a subquery: SELECT MIN(salary) FROM (SELECT DISTINCT TOP N salary FROM employees ORDER BY salary DESC) AS top_n;
Q27. What is a stored procedure? → A pre-compiled SQL code block stored in the database that can be called with parameters. Useful for repetitive operations but less common in analyst workflows.
Q28. What is the difference between a primary key and a foreign key? → A primary key uniquely identifies each row in a table. A foreign key references the primary key of another table to establish a relationship.
Q29. How do you optimize a slow SQL query? → Check execution plan with EXPLAIN, add indexes on JOIN and WHERE columns, avoid SELECT *, reduce subqueries by using CTEs or JOINs, and partition large tables.
Q30. What is a self-join? Give an example. → A self-join joins a table with itself. Example: Find all pairs of employees in the same department.
sql
SELECT a.name, b.name, a.department
FROM employees a
JOIN employees b ON a.department = b.department
WHERE a.employee_id < b.employee_id;
Comparison: SQL Difficulty by Company Type in India 2026
| Company | Difficulty | Focus Areas |
|---|---|---|
| Amazon India | Hard | Window functions, CTEs, business logic |
| Flipkart | Hard | Cohort analysis, funnel queries, growth metrics |
| TCS / Infosys | Medium | JOINs, GROUP BY, subqueries |
| HDFC / ICICI Analytics | Medium–Hard | Aggregations, date functions, fraud patterns |
| Startups (Swiggy, Zepto) | Hard | Complex multi-step analytical queries |
Image Suggestions
Image 1—Placement: After the introduction, a clean laptop screen showing SQL code with JOIN and GROUP BY syntax highlighted in a dark-theme IDE, on a desk in an Indian tech office. ALT text: “SQL interview questions for data analyst India 2026 — SQL code with JOIN and window functions on laptop screen”
Image 2—Placement: After the intermediate section, a whiteboard with a hand-drawn SQL query schema showing table relationships, used during an Indian tech company interview session. ALT text: “SQL interview questions for data analyst India 2026 — SQL table relationships on whiteboard during interview”
External Authority Links
- LeetCode SQL Problems — best platform to practise all levels of SQL interview questions
- Mode Analytics SQL Tutorial—a comprehensive, free SQL learning resource
- HackerRank SQL Practice — widely used for Indian company online assessments
- W3Schools SQL Reference — quick syntax reference for all SQL commands
- Analytics Vidhya — SQL for Data Analysts — India-focused SQL interview guides
FAQs: SQL Interview Questions for Data Analyst India 2026
Q1. Which SQL topics are most important for data analyst interviews in India in 2026? JOINs, GROUP BY with aggregations, window functions (RANK, ROW_NUMBER, LAG, and LEAD), CTEs, subqueries, and date functions are the highest-priority topics in SQL interview questions for data analysts in India in 2026 across all company types.
Q2. Should I learn MySQL or PostgreSQL for data analyst interviews in India? Both are valuable. MySQL is more common in Indian IT services companies and e-commerce. PostgreSQL is increasingly used at product companies and data warehouses. The core SQL interview questions for data analysts in India in 2026 have almost identical syntax—focus on concepts, not dialect.
Q3. How long does it take to prepare SQL for a data analyst interview in India? With 1–2 hours of daily practice on LeetCode and HackerRank, a dedicated beginner can handle most SQL interview questions for data analyst India 2026 within 4–6 weeks. Intermediate learners typically need 2–3 weeks of targeted practice.
Q4. Are window functions always asked in data analyst SQL interviews in India? At product companies (Amazon, Flipkart, Swiggy, Meesho), window functions appear in almost every technical round. At IT services companies, they appear in mid-to-senior role interviews. Mastering window functions is non-negotiable for the hardest SQL interview questions for data analysts in India in 2026.
Q5. How should I practice SQL for interviews—what is the best approach? Practice on LeetCode (start with Easy, move to Medium), write queries on real datasets from Kaggle, and try to solve every SQL interview question for the Data Analyst India 2026 problem in this guide without looking at the answer first. Time yourself — most interviewers expect a working query within 5–10 minutes.
Conclusion
SQL is your most powerful weapon in every data analyst interview in India in 2026. Mastering the 30 SQL interview questions for data analyst India 2026 in this guide — from basic GROUP BY to advanced cohort analysis and fraud detection — will prepare you for every company type, every interview stage, and every difficulty level.
Practice is everything. Write every query in this guide from memory. Run them on a sample database. Understand why each solution works, not just what it does. That depth of understanding is what will make you stand out when answering SQL interview questions for Data Analyst India 2026 under interview pressure.
Which SQL topic do you find most challenging? Drop your question in the comments, and we will help you master it!


