If you’re preparing for a data analyst role, mastering SQL is essential.
Most interviews include practical SQL questions to test your ability to analyze data, not just write syntax.
In this guide, you’ll learn common SQL queries asked in data analyst interviews with clear examples and explanations.
Sample Dataset
Assume a table called orders:
| order_id | customer_id | region | revenue | order_date |
|---|---|---|---|---|
| 1 | 101 | West | 500 | 2026-01-01 |
| 2 | 102 | East | 700 | 2026-01-02 |
| 3 | 101 | West | 300 | 2026-01-03 |
1. Total Revenue
Question:
Calculate total revenue.
SELECT SUM(revenue) AS total_revenue
FROM orders;
2. Revenue by Region
Question:
Find total revenue per region.
SELECT region, SUM(revenue) AS total_revenue
FROM orders
GROUP BY region;
3. Count Orders per Customer
Question:
How many orders does each customer have?
SELECT customer_id, COUNT(*) AS total_orders
FROM orders
GROUP BY customer_id;
4. Top Customers by Revenue
Question:
Find top customers based on revenue.
SELECT customer_id, SUM(revenue) AS total_revenue
FROM orders
GROUP BY customer_id
ORDER BY total_revenue DESC;
5. Filter Recent Orders
Question:
Get orders after a specific date.
SELECT *
FROM orders
WHERE order_date >= '2026-01-01';
6. Average Revenue
Question:
Find average order revenue.
SELECT AVG(revenue) AS avg_revenue
FROM orders;
7. Using CASE WHEN
Question:
Categorize orders based on revenue.
SELECT order_id,
CASE
WHEN revenue > 500 THEN 'High'
ELSE 'Low'
END AS revenue_category
FROM orders;
8. Find Duplicate Customers
Question:
Find customers with more than one order.
SELECT customer_id, COUNT(*) AS order_count
FROM orders
GROUP BY customer_id
HAVING COUNT(*) > 1;
9. Get Top N Records
Question:
Find top 2 highest revenue orders.
SELECT *
FROM orders
ORDER BY revenue DESC
LIMIT 2;
10. Running Total (Window Function)
Question:
Calculate cumulative revenue.
SELECT order_date,
SUM(revenue) OVER (ORDER BY order_date) AS running_total
FROM orders;
11. Rank Customers
Question:
Rank customers by total revenue.
SELECT customer_id,
SUM(revenue) AS total_revenue,
RANK() OVER (ORDER BY SUM(revenue) DESC) AS rank
FROM orders
GROUP BY customer_id;
12. Join Example
Assume another table customers:
| customer_id | name |
Question:
Join orders with customer names.
SELECT o.order_id, c.name, o.revenue
FROM orders o
JOIN customers c
ON o.customer_id = c.customer_id;
What Interviewers Are Testing
These queries test your ability to:
- Aggregate data
- Filter and group results
- Use joins
- Apply business logic
- Work with real-world scenarios
It’s not just about syntax, it’s about solving problems.
How to Prepare for SQL Interviews
- Practice real-world datasets
- Understand concepts like GROUP BY, JOIN, and window functions
- Explain your logic clearly
- Optimize your queries
Interviewers value clarity and reasoning.
Common Mistakes to Avoid
- Forgetting GROUP BY when using aggregation
- Using HAVING instead of WHERE incorrectly
- Not handling NULL values
- Writing inefficient queries
Avoiding these mistakes can set you apart.
SQL is one of the most important skills for data analysts, and interviews are designed to test how well you can use it to solve real problems.
By practicing these common queries, you’ll build confidence and improve your ability to handle real interview questions.
Consistency and practice are key to mastering SQL.
FAQs
What SQL topics are important for data analyst interviews?
SELECT, WHERE, GROUP BY, JOIN, window functions, and aggregation.
Are SQL interviews difficult?
They can be challenging, but practice makes them easier.
How can I prepare for SQL interviews?
Practice real-world questions and understand concepts deeply.
Do I need advanced SQL for interviews?
Basic to intermediate SQL is usually enough.
What do interviewers look for?
Problem-solving skills and clear explanations.