Back to Blog
SQL Interview Questions for Data Analysts article visual22 min read
Tools & Skills

SQL Interview Questions for Data Analysts

Prepare for data analyst SQL interviews with beginner, intermediate, advanced, and scenario-based questions, sample answers, practical queries, and business explanation tips.

17 Jun 202622 min readBrit Institute
Brit Institute guide

Prepare for data analyst SQL interviews with beginner, intermediate, advanced, and scenario-based questions, sample answers, practical queries, and business explanation tips.

15Sections

A focused reading path with clear comparison points and practical next steps.

Best for

Career changers comparing analyst, scientist, BI, and AI-adjacent data roles in the UK.

SQL is one of the most important skills for Data Analyst interviews. Even if a role focuses on Excel, Power BI, Tableau, or reporting, employers often expect analysts to understand how to extract, filter, join, and summarise data from databases.

For entry-level and junior data analyst roles, SQL interviews usually test practical thinking rather than advanced database theory. Interviewers want to know whether you can answer business questions using data.

This guide covers SQL interview questions for Data Analysts with difficulty levels, sample answers, query examples, and explanation tips.

Why SQL Matters for Data Analysts

Most business data is stored in databases. SQL helps analysts access that data and prepare it for reporting, dashboards, and decision-making.

A Data Analyst may use SQL to answer questions such as:

  • Which product generated the highest revenue?
  • How many customers purchased last month?
  • Which region had the lowest sales?
  • What is the average order value?
  • Which customers have not purchased recently?
  • Which employees completed the most tasks?
  • Which marketing campaign performed best?

SQL is valuable because it helps you move from depending on exported spreadsheets to working directly with business data.

What SQL Skills Are Tested in Data Analyst Interviews?

Most Data Analyst SQL interviews focus on these areas:

  • Basic SELECT queries
  • Filtering with WHERE
  • Sorting with ORDER BY
  • Aggregations using COUNT, SUM, AVG, MIN, and MAX
  • Grouping with GROUP BY
  • Filtering grouped results using HAVING
  • Joining tables using INNER JOIN and LEFT JOIN
  • Handling NULL values
  • Using CASE WHEN
  • Working with dates
  • Finding duplicates
  • Using subqueries or common table expressions
  • Basic window functions for ranking and running totals

For junior roles, you do not need to know every advanced SQL concept. You need to show that you can use SQL to solve realistic business problems.

Sample Tables Used in This Guide

Many questions below use these example tables.

orders

columndescription
order_idUnique order ID
customer_idCustomer ID
order_dateDate of order
product_idProduct ID
regionCustomer region
sales_amountOrder value
statusCompleted, Cancelled, Returned

customers

columndescription
customer_idUnique customer ID
customer_nameCustomer name
signup_dateCustomer registration date
segmentRetail, Business, Enterprise
cityCustomer city

products

columndescription
product_idUnique product ID
product_nameProduct name
categoryProduct category
cost_priceProduct cost

Beginner SQL Interview Questions

1. What is SQL?

Difficulty: Beginner

SQL stands for Structured Query Language. It is used to work with data stored in relational databases. Data Analysts use SQL to extract, filter, join, group, and summarise data for reporting and analysis.

Strong interview answer:

"SQL is a language used to communicate with databases. As a Data Analyst, I would use SQL to retrieve specific data, filter records, join tables, calculate totals, and prepare datasets for reports or dashboards."

2. What is the difference between SELECT and WHERE?

Difficulty: Beginner

SELECT chooses the columns you want to see. WHERE filters the rows based on a condition.

Example query:

sqlSELECT
    customer_id,
    sales_amount
FROM orders
WHERE region = 'London';

This query shows customer ID and sales amount only for orders from London.

3. How do you select all columns from a table?

Difficulty: Beginner

sqlSELECT *
FROM orders;

Interview explanation:

"The asterisk means all columns. In real analysis, I would avoid using SELECT * for large datasets unless I need a quick inspection, because selecting only required columns is more efficient and clearer."

4. How do you find total sales?

Difficulty: Beginner

sqlSELECT
    SUM(sales_amount) AS total_sales
FROM orders;

SUM adds all values in the sales_amount column and returns total sales.

5. How do you count the number of orders?

Difficulty: Beginner

sqlSELECT
    COUNT(order_id) AS total_orders
FROM orders;

COUNT counts the number of order IDs. This is commonly used to measure order volume, customer activity, or transaction count.

6. What is the difference between COUNT(*) and COUNT(column_name)?

Difficulty: Beginner

COUNT(*) counts all rows. COUNT(column_name) counts only rows where that column is not NULL.

Strong interview answer:

"COUNT(*) counts every row in the result, while COUNT(column_name) ignores NULL values in that specific column. This matters when checking data completeness or missing values."

7. How do you find unique regions from the orders table?

Difficulty: Beginner

sqlSELECT DISTINCT
    region
FROM orders;

DISTINCT removes duplicate values and shows each region only once.

8. How do you sort results from highest to lowest sales?

Difficulty: Beginner

sqlSELECT
    order_id,
    sales_amount
FROM orders
ORDER BY sales_amount DESC;

ORDER BY sorts the results. DESC means descending order.

Intermediate SQL Interview Questions

9. How do you find total sales by region?

Difficulty: Intermediate

sqlSELECT
    region,
    SUM(sales_amount) AS total_sales
FROM orders
GROUP BY region
ORDER BY total_sales DESC;

This groups orders by region and calculates total sales for each region.

Business interpretation:

"This helps the business compare regional performance and identify stronger or weaker markets."

10. What is GROUP BY used for?

Difficulty: Intermediate

GROUP BY is used to summarise data by categories.

Strong interview answer:

"GROUP BY allows us to calculate metrics for each category. For example, we can group sales by region, product, month, or customer segment and calculate totals, averages, or counts."

11. What is the difference between WHERE and HAVING?

Difficulty: Intermediate

WHERE filters rows before aggregation. HAVING filters grouped results after aggregation.

Example query:

sqlSELECT
    region,
    SUM(sales_amount) AS total_sales
FROM orders
WHERE status = 'Completed'
GROUP BY region
HAVING SUM(sales_amount) > 50000;

WHERE keeps only completed orders before grouping. HAVING keeps only regions where total sales are above 50,000 after grouping.

12. How do you find customers who placed more than five orders?

Difficulty: Intermediate

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

Business interpretation:

"This helps identify repeat customers or loyal customers who may be useful for retention campaigns."

13. What is an INNER JOIN?

Difficulty: Intermediate

INNER JOIN returns only matching records from both tables.

Example query:

sqlSELECT
    o.order_id,
    c.customer_name,
    o.sales_amount
FROM orders o
INNER JOIN customers c
    ON o.customer_id = c.customer_id;

This query returns orders only where the customer exists in both the orders and customers tables.

14. What is a LEFT JOIN?

Difficulty: Intermediate

LEFT JOIN returns all records from the left table and matching records from the right table. If there is no match, the right table columns show NULL.

Example query:

sqlSELECT
    c.customer_id,
    c.customer_name,
    o.order_id,
    o.sales_amount
FROM customers c
LEFT JOIN orders o
    ON c.customer_id = o.customer_id;

This query keeps all customers, even those who have not placed any orders.

Business use case:

"LEFT JOIN is useful when we want to find customers without orders, products without sales, or records missing from another table."

15. How do you find customers who have never placed an order?

Difficulty: Intermediate

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

The LEFT JOIN keeps all customers. The WHERE condition filters only those with no matching order.

Business interpretation:

"This can help the business identify inactive customers or users who signed up but never purchased."

16. How do you calculate average order value?

Difficulty: Intermediate

sqlSELECT
    AVG(sales_amount) AS average_order_value
FROM orders
WHERE status = 'Completed';

Average order value is calculated by taking the average sales amount for completed orders.

Strong interview note:

"For business reporting, I would usually exclude cancelled or returned orders unless the requirement says otherwise."

17. How do you use CASE WHEN in SQL?

Difficulty: Intermediate

CASE WHEN is used to create conditional logic in SQL.

Example query:

sqlSELECT
    order_id,
    sales_amount,
    CASE
        WHEN sales_amount >= 1000 THEN 'High Value'
        WHEN sales_amount >= 500 THEN 'Medium Value'
        ELSE 'Low Value'
    END AS order_value_category
FROM orders;

This query classifies each order into high, medium, or low value based on sales amount.

18. How do you find duplicate customers by email or name?

Difficulty: Intermediate

If the customers table had an email column, the query would be:

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

This groups customers by email and shows only emails that appear more than once.

Business interpretation:

"Duplicate records can affect customer counts, campaign reporting, and revenue analysis, so identifying duplicates is an important data cleaning step."

19. How do you handle NULL values in SQL?

Difficulty: Intermediate

NULL means missing or unknown value. You can check it using IS NULL or replace it using COALESCE.

Example query:

sqlSELECT
    customer_id,
    COALESCE(city, 'Unknown') AS city
FROM customers;

COALESCE replaces NULL city values with "Unknown".

Strong interview answer:

"I would not replace NULL values blindly. First, I would understand why values are missing and how the business wants them handled."

20. How do you calculate monthly sales?

Difficulty: Intermediate

The exact date function depends on the SQL database. A common approach is:

sqlSELECT
    DATE_TRUNC('month', order_date) AS sales_month,
    SUM(sales_amount) AS total_sales
FROM orders
WHERE status = 'Completed'
GROUP BY DATE_TRUNC('month', order_date)
ORDER BY sales_month;

This groups sales by month and calculates total sales for each month.

Note:

In SQL Server, you may use FORMAT, YEAR and MONTH, or DATETRUNC depending on version. In MySQL, you may use DATE_FORMAT.

Advanced SQL Interview Questions

21. How do you find the top 3 products by sales?

Difficulty: Advanced

sqlSELECT
    p.product_name,
    SUM(o.sales_amount) AS total_sales
FROM orders o
INNER JOIN products p
    ON o.product_id = p.product_id
WHERE o.status = 'Completed'
GROUP BY p.product_name
ORDER BY total_sales DESC
LIMIT 3;

This joins orders with products, calculates total sales by product, sorts the result, and returns the top 3 products.

SQL Server version:

sqlSELECT TOP 3
    p.product_name,
    SUM(o.sales_amount) AS total_sales
FROM orders o
INNER JOIN products p
    ON o.product_id = p.product_id
WHERE o.status = 'Completed'
GROUP BY p.product_name
ORDER BY total_sales DESC;

22. How do you find the second highest order value?

Difficulty: Advanced

sqlSELECT
    MAX(sales_amount) AS second_highest_order_value
FROM orders
WHERE sales_amount < (
    SELECT MAX(sales_amount)
    FROM orders
);

The subquery finds the highest sales amount. The outer query finds the maximum value below that highest amount.

23. How do you rank products by revenue?

Difficulty: Advanced

sqlSELECT
    p.product_name,
    SUM(o.sales_amount) AS total_revenue,
    RANK() OVER (ORDER BY SUM(o.sales_amount) DESC) AS revenue_rank
FROM orders o
INNER JOIN products p
    ON o.product_id = p.product_id
WHERE o.status = 'Completed'
GROUP BY p.product_name;

RANK assigns a rank based on total revenue. If two products have the same revenue, they receive the same rank.

24. What is the difference between RANK, DENSE_RANK, and ROW_NUMBER?

Difficulty: Advanced

ROW_NUMBER gives a unique number to each row. RANK gives the same rank to tied values and skips the next rank. DENSE_RANK gives the same rank to tied values but does not skip ranks.

Example:

  • If sales values are 100, 90, 90, 80
  • ROW_NUMBER: 1, 2, 3, 4
  • RANK: 1, 2, 2, 4
  • DENSE_RANK: 1, 2, 2, 3

Strong interview answer:

"These functions are useful for ranking products, customers, employees, or regions based on performance metrics."

25. How do you calculate running total sales by date?

Difficulty: Advanced

sqlSELECT
    order_date,
    SUM(sales_amount) AS daily_sales,
    SUM(SUM(sales_amount)) OVER (
        ORDER BY order_date
    ) AS running_total_sales
FROM orders
WHERE status = 'Completed'
GROUP BY order_date
ORDER BY order_date;

The first SUM calculates daily sales. The window function calculates the cumulative running total over time.

Business use case:

"This helps track cumulative monthly or yearly revenue performance."

26. How do you find month-over-month sales growth?

Difficulty: Advanced

sqlWITH monthly_sales AS (
    SELECT
        DATE_TRUNC('month', order_date) AS sales_month,
        SUM(sales_amount) AS total_sales
    FROM orders
    WHERE status = 'Completed'
    GROUP BY DATE_TRUNC('month', order_date)
)
SELECT
    sales_month,
    total_sales,
    LAG(total_sales) OVER (ORDER BY sales_month) AS previous_month_sales,
    ROUND(
        100.0 * (total_sales - LAG(total_sales) OVER (ORDER BY sales_month))
        / NULLIF(LAG(total_sales) OVER (ORDER BY sales_month), 0),
        2
    ) AS month_over_month_growth_percentage
FROM monthly_sales
ORDER BY sales_month;

This query first calculates monthly sales. Then it uses LAG to compare each month with the previous month.

Business interpretation:

"This helps identify whether revenue is growing or declining month by month."

27. How do you find the highest spending customer in each region?

Difficulty: Advanced

sqlWITH customer_sales AS (
    SELECT
        c.customer_id,
        c.customer_name,
        o.region,
        SUM(o.sales_amount) AS total_sales
    FROM orders o
    INNER JOIN customers c
        ON o.customer_id = c.customer_id
    WHERE o.status = 'Completed'
    GROUP BY c.customer_id, c.customer_name, o.region
),
ranked_customers AS (
    SELECT
        customer_id,
        customer_name,
        region,
        total_sales,
        RANK() OVER (
            PARTITION BY region
            ORDER BY total_sales DESC
        ) AS customer_rank
    FROM customer_sales
)
SELECT
    customer_id,
    customer_name,
    region,
    total_sales
FROM ranked_customers
WHERE customer_rank = 1;

This query calculates customer sales by region, ranks customers inside each region, and returns the top customer per region.

28. How do you identify inactive customers?

Difficulty: Advanced

sqlSELECT
    c.customer_id,
    c.customer_name,
    MAX(o.order_date) AS last_order_date
FROM customers c
LEFT JOIN orders o
    ON c.customer_id = o.customer_id
GROUP BY c.customer_id, c.customer_name
HAVING MAX(o.order_date) < CURRENT_DATE - INTERVAL '90 days'
    OR MAX(o.order_date) IS NULL;

This query finds customers whose last order was more than 90 days ago or who never placed an order.

Business use case:

"This is useful for retention campaigns and customer reactivation."

29. How do you calculate customer lifetime value using SQL?

Difficulty: Advanced

sqlSELECT
    c.customer_id,
    c.customer_name,
    SUM(o.sales_amount) AS customer_lifetime_value
FROM customers c
INNER JOIN orders o
    ON c.customer_id = o.customer_id
WHERE o.status = 'Completed'
GROUP BY c.customer_id, c.customer_name
ORDER BY customer_lifetime_value DESC;

Customer lifetime value here is calculated as total completed sales by customer.

Strong interview note:

"In a real business, customer lifetime value may include cost, margin, repeat purchase rate, and predicted future value, depending on the company's definition."

30. How do you check revenue contribution by product category?

Difficulty: Advanced

sqlWITH category_sales AS (
    SELECT
        p.category,
        SUM(o.sales_amount) AS category_revenue
    FROM orders o
    INNER JOIN products p
        ON o.product_id = p.product_id
    WHERE o.status = 'Completed'
    GROUP BY p.category
),
total_sales AS (
    SELECT
        SUM(category_revenue) AS total_revenue
    FROM category_sales
)
SELECT
    cs.category,
    cs.category_revenue,
    ROUND(
        100.0 * cs.category_revenue / ts.total_revenue,
        2
    ) AS revenue_contribution_percentage
FROM category_sales cs
CROSS JOIN total_sales ts
ORDER BY revenue_contribution_percentage DESC;

This query calculates each category's share of total revenue.

Business interpretation:

"This helps identify which product categories drive the largest share of business revenue."

Scenario-Based SQL Interview Questions

31. Sales dropped last month. What SQL analysis would you perform?

Difficulty: Intermediate to Advanced

A strong analyst would not look only at total sales. They would break the problem down.

Possible SQL checks:

  • Sales by month
  • Sales by region
  • Sales by product category
  • Sales by customer segment
  • Cancelled or returned orders
  • Average order value
  • Number of orders
  • Top customer changes

Sample query:

sqlSELECT
    DATE_TRUNC('month', order_date) AS sales_month,
    region,
    SUM(sales_amount) AS total_sales,
    COUNT(order_id) AS total_orders,
    AVG(sales_amount) AS average_order_value
FROM orders
WHERE status = 'Completed'
GROUP BY DATE_TRUNC('month', order_date), region
ORDER BY sales_month, total_sales DESC;

Strong interview answer:

"I would first confirm that the sales drop is real and not caused by missing data or filter changes. Then I would compare monthly sales by region, product, customer segment, and order count. I would check whether the drop was caused by fewer orders, lower average order value, product performance, cancellations, or a specific region."

32. A dashboard number does not match the database. What would you check?

Difficulty: Intermediate

Strong answer:

"I would check the data source, filters, refresh date, joins, duplicate records, calculation logic, and whether cancelled or returned orders are included. I would also compare the dashboard measure with a direct SQL query to validate the number."

Example validation query:

sqlSELECT
    SUM(sales_amount) AS completed_sales
FROM orders
WHERE status = 'Completed';

33. How would you prepare data for a Power BI dashboard using SQL?

Difficulty: Intermediate

Strong answer:

"I would first understand the dashboard requirements and KPIs. Then I would write SQL queries to prepare clean, summarised, dashboard-ready tables. I would include required columns such as date, region, product, customer segment, sales, order count, and profit if available. I would also check duplicates, missing values, and date formats before connecting the data to Power BI."

Practise SQL with Real Analyst Scenarios

Build job-ready SQL, Excel, Power BI, dashboard, and interview skills through practical data analytics training.

SQL Concepts Every Data Analyst Should Explain Clearly

Primary key

A primary key uniquely identifies each row in a table.

Example: customer_id in the customers table.

Foreign key

A foreign key connects one table to another.

Example: customer_id in the orders table connects orders to customers.

Aggregate functions

Aggregate functions summarise data.

Examples: COUNT, SUM, AVG, MIN, MAX.

JOIN

A JOIN combines data from multiple tables.

Examples: INNER JOIN, LEFT JOIN, RIGHT JOIN, FULL JOIN.

NULL

NULL means missing or unknown value.

Subquery

A subquery is a query inside another query.

CTE

A common table expression is a temporary named result that makes complex queries easier to read.

Window function

A window function performs calculations across a set of rows without collapsing them into one row.

Examples: ROW_NUMBER, RANK, LAG, running totals.

Difficulty-Level Preparation Roadmap

Beginner level

Focus on:

  • SELECT
  • WHERE
  • ORDER BY
  • COUNT
  • SUM
  • AVG
  • DISTINCT
  • Basic filtering

You should be able to extract specific rows and columns and calculate basic totals.

Intermediate level

Focus on:

  • GROUP BY
  • HAVING
  • INNER JOIN
  • LEFT JOIN
  • CASE WHEN
  • NULL handling
  • Date functions
  • Duplicate checks

You should be able to answer practical business questions using multiple tables.

Advanced level

Focus on:

  • Subqueries
  • CTEs
  • Window functions
  • Ranking
  • Running totals
  • Month-over-month analysis
  • Customer segmentation
  • Performance checks

You should be able to write structured queries for business analysis and dashboard preparation.

How to Answer SQL Questions in an Interview

Do not jump directly into writing the query. A strong candidate explains their thinking.

Use this structure:

  • Understand the business question
  • Identify the table or columns needed
  • Apply filters
  • Join tables if required
  • Group or aggregate the data
  • Sort or rank the result
  • Explain what the output means

Example:

Question: Find the top 5 customers by revenue.

Strong answer:

"I would use the orders table, filter for completed orders, group by customer, calculate total revenue using SUM, sort the result in descending order, and limit it to the top 5 customers."

sqlSELECT
    customer_id,
    SUM(sales_amount) AS total_revenue
FROM orders
WHERE status = 'Completed'
GROUP BY customer_id
ORDER BY total_revenue DESC
LIMIT 5;

Common SQL Interview Mistakes to Avoid

Mistake 1: Not understanding the business question

Before writing SQL, understand what the interviewer is asking.

Mistake 2: Forgetting GROUP BY

If you use aggregate functions with category columns, you usually need GROUP BY.

Mistake 3: Confusing WHERE and HAVING

WHERE filters rows before grouping. HAVING filters grouped results.

Mistake 4: Using INNER JOIN when LEFT JOIN is needed

If you need to keep all records from one table, use LEFT JOIN.

Mistake 5: Ignoring NULL values

NULL values can change counts, averages, and business interpretation.

Mistake 6: Not explaining the query

Interviewers want to understand your logic, not just see the final query.

Mistake 7: Overcomplicating simple questions

Use the simplest correct query first. Add complexity only when needed.

SQL Interview Practice Checklist

Before attending a Data Analyst interview, make sure you can confidently do the following:

  • Write SELECT queries
  • Filter rows using WHERE
  • Sort results using ORDER BY
  • Calculate totals and averages
  • Group data by category
  • Use HAVING after GROUP BY
  • Join two or more tables
  • Explain INNER JOIN and LEFT JOIN
  • Handle NULL values
  • Use CASE WHEN
  • Find duplicates
  • Calculate monthly sales
  • Rank products or customers
  • Explain your query step by step
  • Connect SQL output to business decisions

Final Advice for Data Analyst SQL Interviews

SQL interviews are not only about syntax. They are about problem-solving.

A strong Data Analyst should be able to look at a business question and translate it into a query.

The interviewer wants to see:

  • Can you understand the question?
  • Can you choose the right table?
  • Can you apply the correct filters?
  • Can you join data correctly?
  • Can you summarise the result?
  • Can you explain what the output means?

If you can write clear queries and explain your thinking in business language, you will perform much better in Data Analyst interviews.

Prepare for Data Analyst Interviews with Brit Institute

Brit Institute helps learners build practical SQL skills for real data analyst roles.

Our Data Analytics training focuses on:

  • SQL fundamentals
  • Business case studies
  • Data cleaning
  • Excel reporting
  • Power BI dashboards
  • Portfolio projects
  • Interview preparation
  • CV and LinkedIn guidance
  • Project explanation practice

The goal is not only to learn SQL commands. The goal is to become confident using SQL to solve real business problems.

Start Your Interview Preparation

Explore the Data Analytics Programme, book a free career guidance call, download the curriculum, or speak to a career advisor to plan your interview preparation.

Frequently Asked Questions

Data analyst SQL interviews commonly include SELECT, WHERE, ORDER BY, GROUP BY, HAVING, aggregate functions, INNER JOIN, LEFT JOIN, NULL handling, CASE WHEN, date functions, duplicates, subqueries, CTEs, and window functions.

A beginner data analyst should be comfortable extracting columns, filtering rows, sorting results, calculating totals and averages, grouping data, joining tables, handling NULL values, and explaining the business meaning of a query.

Some interviews include advanced SQL such as CTEs, ranking, running totals, LAG, month-over-month growth, customer segmentation, and top-N queries, especially for junior-to-mid analyst roles.

Explain the business question, tables and columns used, filters, joins, aggregations, sorting or ranking, and what the final output means for the business decision.

Recommended Programmes

Continue from this guide into structured training built around UK career outcomes.

Prepare for Data Analyst Interviews with Brit Institute

Learn SQL fundamentals, business case studies, data cleaning, Power BI dashboards, portfolio projects, CV guidance, and interview preparation.

Related Articles

🎓Need Help? Get Career Guidance|Call Us at7447 177848orBOOK FREE CONSULTATION »