10 advanced
SQL interview
practical
query
questions
along with
their solutions
1. Question: Retrieve the top 5 highest-paid employees for each
department, sorted by salary in descending order.
Solution
2. Question: Calculate the total sales for each month of the
current year, including months with zero sales.
3. Question: Find customers who have made a purchase every
month for the last six months.
4. Question: Calculate the running total of sales for each day
within the past month.
5. Question: List the products that have been sold in all cities
where the company operates.
6. Question: Retrieve the top 10 customers who have spent the
most on their single purchase.
7. Question: Find the employees who manage the same number
of employees as their manager.
8. Question: Calculate the 30-day moving average of sales for each
product.
9. Question: List the departments where the average salary is
higher than the company's overall average salary.
10. Question: Retrieve the top 3 most recent orders for each
customer.