DataBolt

All Lessons

Introduction to SQL
SQL Lesson 1: Your Sample Database
SQL Lesson 2: SELECT — Reading data
SQL Lesson 3: WHERE — Filtering rows
SQL Lesson 4: AND, OR, NOT
SQL Lesson 5: BETWEEN, IN, LIKE
SQL Lesson 6: NULL — The Mystery Value
SQL Lesson 7: ORDER BY
SQL Lesson 8: LIMIT & OFFSET
SQL Lesson 9: Aggregate Functions
SQL Lesson 10: GROUP BY
SQL Lesson 11: HAVING
SQL Lesson 12: INNER JOINs
SQL Lesson 13: LEFT JOINs
SQL Lesson 14: RIGHT JOINs
SQL Lesson 15: SELF JOINs
SQL Lesson 16: UNION JOINs
SQL Lesson 17: Joining Multiple Tables
SQL Lesson 18: Subqueries
SQL Lesson 19: CTEs (WITH)
SQL Lesson 20: CASE Statements
SQL Lesson 21: Window Functions
SQL Lesson 22: String Functions
SQL Lesson 23: Date & Time Functions
SQL Lesson 24: INSERT, UPDATE, DELETE
SQL Lesson 25: CREATE TABLE & DDL
SQL Lesson 26: Indexes & Performance
SQL Lesson 27: Transactions & ACID
SQL Lesson 28: SQL Execution Order
SQL Lesson 29: 50 Practice Problems

CHAPTER 30

50 Practice Problems

Build real query muscle — from beginner to FAANG-ready.

IN THIS CHAPTER

  • Section A (Q1 - 15): Beginner - single table, basic filters
  • Section B (Q16 - 35): Intermediate — JOINs, GROUP BY, subqueries
  • Section C (Q36 - 50): Advanced — window functions, CTEs, analytics

All problems use our five tables: employees, products, customers, orders, order_items.

🌟 Note Attempt each question before looking at the Answer Key. Struggling and figuring out the answer yourself is 10x more effective than reading the solution directly.

Included Tables in Exercise

Table: Employees

emp_idnamedepartmentsalarymanager_idhire_date
1ArjunIT85000NULL2020-06-15
2PriyaIT7200012021-03-10
3RahulSales5500052022-01-20
4SnehaHR6000052021-07-08
5VikramSales90000NULL2019-11-01
6DivyaIT6800012023-02-14
7KiranHR5800042022-08-30
8MeeraSales6200052023-05-12

Table: Order Items

item_idorder_idproduct_idqtyunit_price
111179999
22312999
3221499
435165000
5421499
654299
756150
86312999

Table: Orders

order_idcustomer_idorder_datetotalstatus
112024-01-1579999completed
222024-01-203498completed
312024-02-1065000completed
432024-02-14499pending
522024-03-01248completed
652024-03-152999shipped
712024-04-05149completed

Table: Products

product_idnamecategorypricestock
1iPhone 15Electronics7999950
2SQL BookBooks499200
3HeadphonesElectronics299975
4NotebookStationery99500
5LaptopElectronics6500020
6Pen SetStationery1490
7MouseElectronics59925

Table: Customers

customer_idnamecitycountry
1AnanyaHyderabadIndia
2RohanBangaloreIndia
3SamMumbaiIndia
4LisaLondonUK
5RaviDelhiIndia

Exercise 👇

Exercise:

Tasks

1.👉List all employees with their department and salary.
2.Show only the name and hire_date of every employee.
3.Find all employees in the 'Sales' department.
4.List all products with price under ₹1,000.
5.Find all customers from India.
6.Show employees hired after 2022-01-01.
7.List all distinct product categories.
8.Find orders with status = 'pending'.
9.Find employees whose name starts with 'A'.
10.Find products that are out of stock (stock = 0).
11.List all employees sorted by salary — highest first.
12.Show the top 3 most expensive products.
13.Find employees with salary between ₹60,000 and ₹80,000.
14.List employees NOT in the 'IT' department.
15.Find employees who have a manager (manager_id is not null).
16.Count how many employees are in each department.
17.What is the average salary per department, ordered highest first?
18.Which department has the highest total payroll?
19.How many orders has each customer placed? (include customers with 0 orders)
20.What is the total revenue from all completed orders?
21.Show each employee's name and their manager's name.
22.Which customers have placed at least one order?
23.Which customers have NEVER placed an order?
24.Show each order with the customer name.
25.List each order item with customer name, product name, qty, unit price.
26.Find products that have been ordered at least once.
27.Find products that have NEVER been ordered.
28.Show total revenue per customer, highest first.
29.Which month had the highest revenue in 2024?
30.Find employees earning more than the overall average salary.
31.Find employees earning more than their own department average.
32.Show departments with more than 2 employees.
33.Get the 2nd highest salary in the company.
34.List all January 2024 orders placed by Indian customers.
35.Find customers who placed orders in both January AND February 2024.
36.Rank employees within each department by salary (highest = rank 1).
37.Show only the top earner per department.
38.Show a running cumulative total of order amounts by date.
39.For each order, show the previous order's total (LAG).
40.Calculate month-over-month revenue change (absolute + % change) for 2024.
41.Show each order's total as a percentage of the company's total revenue.
42.Label each customer as VIP (>₹1,00,000), Regular (>₹10,000), or New.
43.Find which product has generated the most total revenue.
44.Show all employees with their full hierarchy level (recursive CTE).
45.Show product category revenue and each category's % share of total.
46.For each employee, show their salary rank within the company (NTILE quartile).
47.Show the 3-month moving average of monthly revenue.
48.Find which day of the week has the most orders.
49.Show each order with a 'streak number' — consecutive orders by the same customer.
50.Build a complete customer health report: name, total orders, total spent, avg order value, days since first order, days since last order.
Stuck? Read this task's