■ 50 Must-Do SQL Interview Questions
1. Select all employees whose salary is greater than 50,000.
2. Find employees who joined in the last 30 days.
3. Retrieve distinct department names from the employee table.
4. Sort employees by salary in descending order.
5. Count the number of employees in each department.
6. Find employees whose name starts with ‘A’.
7. Retrieve top 3 highest-paid employees.
8. Write a query to find NULL values in a column.
9. Display employees who don’t have a manager assigned.
10. Difference between WHERE and HAVING? Write queries for both.
11. Write a query to get employees along with their department names.
12. Find employees who don’t belong to any department.
13. List all departments and the number of employees in each.
14. Get employees and their manager’s name (self join).
15. Find customers who placed orders in the last 7 days.
16. Write a query to fetch employees working in more than one project.
17. Difference between INNER JOIN and LEFT JOIN with examples.
18. Find products ordered by more than 5 unique customers.
19. Retrieve employees who never made a sale (anti join).
20. Write a query using CROSS JOIN.
21. Find the second highest salary.
22. Get Nth highest salary (N=3).
23. List departments where average salary > 60,000.
24. Find employees earning more than department average.
25. Write a query to calculate running total of sales.
26. Find employees whose salary is above company average.
27. Get employees with the same salary.
28. Find employees who earn more than their manager.
29. Get the difference between max and min salary in each department.
30. Find employees whose salary is in top 10% overall.
31. Write a query to rank employees by salary within each department.
32. Find the first and last order date of each customer.
33. Calculate 7-day moving average of sales.
34. Find employees whose salary decreased compared to last year.
35. Identify customers with 3 consecutive failed transactions.
36. Get the previous and next salary for each employee using LAG and LEAD.
37. Calculate retention: users who logged in on D1, D7, and D30.
38. Find running average of employee salaries.
39. Find employees with highest salary in each department using window functions
(not subqueries).
40. Show rank vs dense_rank difference with example.
41. Write a query to calculate churn rate of customers.
42. Build a funnel: impression → click → add-to-cart → purchase.
43. Calculate conversion rate at each funnel stage.
44. Find repeat purchase rate of customers.
45. Identify power users (5+ logins per week).
46. Find inactive users in the last 60 days.
47. Calculate Customer Lifetime Value (CLV).
48. Find average time between two purchases per user.
49. Get drop-off rate between two funnel steps.
50. Identify users who upgraded from free → paid plan.