Real-World SQL Interview Questions for Data Analysts ?

Rate this post

Preparing for a Data Analyst interview? Learning SQL syntax is only the first step. In real interviews, companies often give you business situations and ask you to solve them using SQL.

You may be asked to find customers who have never purchased, identify the best-selling products, calculate monthly revenue, or find employees earning more than their department average.

These real-world SQL interview questions help interviewers understand whether you can use SQL to solve practical data problems.

Why Are Real-World SQL Questions Important?

In a real Data Analyst job, you usually do not receive a question like “Write a query using GROUP BY.” Instead, you receive a business problem and need to decide which SQL concepts can solve it.

For example, a sales manager may ask:

“Which five products generated the highest revenue last month?”

To answer this, you may need to use:

  • WHERE for filtering dates
  • GROUP BY for products
  • SUM() for revenue
  • ORDER BY for sorting
  • LIMIT for selecting the top five

This is why practical SQL preparation is important for Data Analyst interviews.

1. Find the Second-Highest Salary

Interview Question:
You have an employee table with employee ID, employee name, department, and salary. Find the second-highest salary.

A common solution is to use DENSE_RANK().

SELECT employee_name, salary
FROM (
    SELECT employee_name,
           salary,
           DENSE_RANK() OVER (ORDER BY salary DESC) AS rnk
    FROM employees
) t
WHERE rnk = 2;

What This Question Tests

SQL ConceptWhy It Matters
DENSE_RANK()Finds salary rankings
ORDER BYSorts salaries
SubqueryHelps filter the ranked result
Window FunctionUseful for analytical problems

This question is especially useful because multiple employees can have the same salary.


2. Find Customers Who Never Placed an Order

Interview Question:
You have customers and orders tables. Find customers who have registered but never placed an order.

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

The key concept here is the LEFT JOIN.

It keeps every customer from the customer table. When there is no matching order, the order columns contain NULL.

Why Businesses Use This Analysis

  • Identify inactive customers
  • Create targeted marketing campaigns
  • Understand customer conversion
  • Improve customer retention strategies

3. Find the Top 5 Products by Sales

Interview Question:
A company wants to know which five products generated the most revenue.

Suppose the sales table contains:

ColumnMeaning
product_idProduct identifier
quantityNumber of products sold
pricePrice per product

You can calculate revenue using:

SELECT product_id,
       SUM(quantity * price) AS total_sales
FROM sales
GROUP BY product_id
ORDER BY total_sales DESC
LIMIT 5;

This query first calculates the total sales for every product and then sorts the products from highest to lowest.


4. Calculate Monthly Revenue

Interview Question:
How would you calculate total revenue for each month?

SELECT
    EXTRACT(YEAR FROM order_date) AS year,
    EXTRACT(MONTH FROM order_date) AS month,
    SUM(quantity * price) AS revenue
FROM orders
GROUP BY
    EXTRACT(YEAR FROM order_date),
    EXTRACT(MONTH FROM order_date)
ORDER BY year, month;

Monthly revenue analysis is commonly used in business dashboards and management reports.

You Should Understand

  • How to extract month and year from dates
  • How to group data by time
  • How to calculate revenue
  • How to sort results chronologically

5. Find Employees Earning More Than Their Department Average

Interview Question:
Find employees whose salary is higher than the average salary of their department.

SELECT employee_name,
       department_id,
       salary
FROM employees e
WHERE salary > (
    SELECT AVG(salary)
    FROM employees
    WHERE department_id = e.department_id
);

This is a good interview question because the average salary must be calculated separately for each department.

For example:

DepartmentAverage Salary
Sales₹55,000
Marketing₹60,000
IT₹75,000

An employee should be compared with the average of their own department, not the company-wide average.


6. Find Duplicate Customer Records

Interview Question:
A company suspects that some customers have been entered more than once. Find duplicate email addresses.

SELECT email,
       COUNT(*) AS duplicate_count
FROM customers
GROUP BY email
HAVING COUNT(*) > 1;

This is a common data-cleaning task for Data Analysts.

Important SQL Concept

WHERE filters individual rows before grouping, while HAVING filters grouped results.

That difference is frequently tested during SQL interviews.


7. Find the Highest-Selling Product in Each Category

Interview Question:
Find the product with the highest sales in every category.

SELECT product_id,
       category,
       total_sales
FROM (
    SELECT product_id,
           category,
           SUM(quantity * price) AS total_sales,
           RANK() OVER (
               PARTITION BY category
               ORDER BY SUM(quantity * price) DESC
           ) AS rnk
    FROM sales
    GROUP BY product_id, category
) t
WHERE rnk = 1;

Here, PARTITION BY is important because it creates a separate ranking for every category.

Example

CategoryTop Product
ElectronicsLaptop
FurnitureOffice Chair
ClothingJacket

This type of question is useful for testing your knowledge of window functions.


8. Find Customers Who Purchased More Than Once

Interview Question:
Find customers who have placed two or more orders.

SELECT customer_id,
       COUNT(order_id) AS order_count
FROM orders
GROUP BY customer_id
HAVING COUNT(order_id) > 1;

Companies can use this type of analysis to understand repeat purchasing behavior.

It can also help identify customers who may be suitable for loyalty programs or retention campaigns.


9. Calculate a Running Total of Sales

Interview Question:
A company wants to see how sales accumulate over time. Calculate the running total.

SELECT order_date,
       sales_amount,
       SUM(sales_amount) OVER (
           ORDER BY order_date
       ) AS running_total
FROM daily_sales;

A running total is different from a normal SUM() because it keeps accumulating as the dates progress.

Running Total Can Be Used For

  • Sales dashboards
  • Revenue tracking
  • Monthly performance reports
  • Financial analysis
  • Business growth monitoring

10. Find Customers Who Purchased in Both January and February

Interview Question:
Find customers who placed an order in both January and February.

One approach is:

SELECT customer_id
FROM orders
WHERE order_date >= '2026-01-01'
  AND order_date < '2026-03-01'
GROUP BY customer_id
HAVING COUNT(
    DISTINCT EXTRACT(MONTH FROM order_date)
) = 2;

This question tests your ability to work with dates, grouping, and conditional business logic.

The same concept can be used to analyze customers who purchased across multiple months or quarters.


11. Find the Third-Highest Salary in Each Department

Interview Question:
Find the third-highest salary in every department.

SELECT employee_name,
       department_id,
       salary
FROM (
    SELECT employee_name,
           department_id,
           salary,
           DENSE_RANK() OVER (
               PARTITION BY department_id
               ORDER BY salary DESC
           ) AS rnk
    FROM employees
) t
WHERE rnk = 3;

This question combines two important concepts:

ConceptPurpose
PARTITION BYSeparates employees by department
DENSE_RANK()Creates salary rankings
ORDER BYSorts salaries
SubqueryFilters the third-ranked records

12. Find Employees Who Joined in the Last 30 Days

Interview Question:
Find employees who joined the company within the last 30 days.

For databases that support this syntax:

SELECT employee_id,
       employee_name,
       joining_date
FROM employees
WHERE joining_date >= CURRENT_DATE - INTERVAL '30 days';

Date-related SQL questions are common because analysts frequently work with employee, customer, sales, and transaction dates.

Common Date Questions

  • Sales from the previous month
  • Customers registered this week
  • Employees who joined this year
  • Orders placed during the last 30 days
  • Year-over-year sales

13. Calculate Each Product’s Percentage of Total Sales

Interview Question:
Find what percentage of total sales comes from each product.

SELECT product_id,
       SUM(sales_amount) AS product_sales,
       SUM(sales_amount) * 100.0 /
       SUM(SUM(sales_amount)) OVER () AS sales_percentage
FROM sales
GROUP BY product_id;

This type of analysis helps businesses understand how individual products contribute to overall revenue.

For example:

ProductSalesContribution
Product A₹5,00,00050%
Product B₹3,00,00030%
Product C₹2,00,00020%

14. Find the Most Recent Order for Every Customer

Interview Question:
Find the latest order placed by each customer.

SELECT customer_id,
       order_id,
       order_date
FROM (
    SELECT customer_id,
           order_id,
           order_date,
           ROW_NUMBER() OVER (
               PARTITION BY customer_id
               ORDER BY order_date DESC
           ) AS rn
    FROM orders
) t
WHERE rn = 1;

This is a practical customer-analysis problem.

Companies can use similar queries to understand:

  • When customers last purchased
  • Which customers are recently active
  • Customer engagement
  • Customer retention

15. Find Missing Dates in Sales Data

Interview Question:
A company expects sales data for every day, but some dates are missing. How would you identify them?

This is a common data-quality problem.

In real projects, analysts often use a calendar or date table and compare it against the sales data.

For example:

DateSales Record
Jan 1Available
Jan 2Available
Jan 3Missing
Jan 4Available

The goal is not just to write SQL but to understand that missing data can affect reports, dashboards, and business decisions.


Important SQL Topics to Prepare

If you are preparing for a Data Analyst interview, don’t only memorize these queries. Understand the SQL concepts behind them.

TopicWhat You Should Practice
JoinsINNER JOIN, LEFT JOIN
AggregationSUM(), AVG(), COUNT()
FilteringWHERE, HAVING
RankingRANK(), DENSE_RANK()
Window FunctionsROW_NUMBER(), running totals
SubqueriesNested queries
CTEsBreaking complex queries into steps
DatesMonthly and yearly analysis
CASEConditional calculations
NULL ValuesMissing-data handling

How to Prepare for Real-World SQL Interviews

A good SQL preparation strategy is to practice problems based on actual business situations.

Instead of only asking yourself, “How does GROUP BY work?”, try questions such as:

  • Which customers generated the most revenue?
  • Which products are selling the fastest?
  • Which customers have never purchased?
  • Which employees earn more than their department average?
  • What was the company’s revenue last month?
  • Which customers have not ordered recently?
  • What percentage of sales comes from each product?
  • Which product performs best in each category?

These questions help you develop the problem-solving skills required in real Data Analyst roles.

Final Thoughts

Real-world SQL interview questions are different from basic SQL exercises because they connect SQL with business problems.

During an interview, the interviewer may give you a situation involving customers, sales, employees, products, or revenue and ask you to find a solution.

To prepare effectively, focus on understanding:

  • Joins
  • Aggregations
  • Subqueries
  • CTEs
  • Window functions
  • Date functions
  • CASE WHEN
  • NULL handling
  • Data-cleaning techniques

Most importantly, don’t just memorize the final query. Understand why the query works and when you would use it.

The more business-based SQL problems you practice, the more comfortable you will become with practical Data Analyst interviews.

Frequently Asked Questions

1. What are real-world SQL interview questions?

Real-world SQL interview questions are practical problems based on situations such as sales analysis, customer behavior, employee data, revenue reporting, and data cleaning.

2. Which SQL topics are important for Data Analyst interviews?

Joins, GROUP BY, aggregate functions, subqueries, CTEs, window functions, date functions, CASE WHEN, and NULL handling are important topics to practice.

3. Are SQL window functions important for interviews?

Yes. Window functions such as ROW_NUMBER(), RANK(), and DENSE_RANK() are useful for ranking, finding latest records, calculating running totals, and solving other analytical problems.

4. How should beginners practice SQL interview questions?

Start with basic filtering and aggregation, then move to joins, subqueries, CTEs, and window functions. Practice using business scenarios instead of only theoretical SQL exercises.

5. What is the best way to prepare for a SQL interview?

Practice solving problems without immediately looking at the answer. First understand the business requirement, identify the tables and columns needed, decide which SQL concepts apply, and then write the query.

Leave a Reply

Your email address will not be published. Required fields are marked *