30 SQL Basic Exercises for Intermediate with Solutions Master intermediate SQL skills with our comprehensive list of top 30 exercises. Dive into coding challenges that improve your understanding and proficiency in SQL, setting a solid foundation for advanced challenges. Start your journey to SQL mastery today!
Learning Objectives:
By the end of these exercises, you will be proficient in intermediate SQL concepts, such as complex joins, subqueries, aggregations, and conditional expressions.
Exercise Instructions:
Start with the first exercise and attempt to solve it before checking the hint or solution.
Ensure you understand the logic behind each solution, as this will help you in more complex problems.
Use these exercises to reinforce your learning and identify areas that may require further study.
1. Retrieve all products priced above the average price.
Code In Sql
-- Table Name : Products
-- Product_ID | Product_Name | Category | Price | Stock
-- ------------+ -------------+-------------+-------+-------
-- 1 | Laptop | Electronics | 55000 | 15
-- 2 | Mobile Phone | Electronics | 30000 | 30
-- 3 | Office Chair | Furniture | 7000 | 10
-- 4 | Coffee Maker | Appliances | 4000 | 20
-- 5 | Dining Table | Furniture | 15000 | 5
-- Your Query Here
Hint Solution Run
Click Run Button to view compiled output
2. Display products in the Furniture category, ordered by price descending.
Code In Sql
-- Table Name : Products
-- Product_ID | Product_Name | Category | Price | Stock
-- ------------+ -------------+-------------+-------+-------
-- 1 | Laptop | Electronics | 55000 | 15
-- 2 | Mobile Phone | Electronics | 30000 | 30
-- 3 | Office Chair | Furniture | 7000 | 10
-- 4 | Coffee Maker | Appliances | 4000 | 20
-- 5 | Dining Table | Furniture | 15000 | 5
-- Your Query Here
Hint Solution Run
Click Run Button to view compiled output
3. Find the total stock available across all products.
Code In Sql
-- Table Name : Products
-- Product_ID | Product_Name | Category | Price | Stock
-- ------------+ -------------+-------------+-------+-------
-- 1 | Laptop | Electronics | 55000 | 15
-- 2 | Mobile Phone | Electronics | 30000 | 30
-- 3 | Office Chair | Furniture | 7000 | 10
-- 4 | Coffee Maker | Appliances | 4000 | 20
-- 5 | Dining Table | Furniture | 15000 | 5
-- Your Query Here
Hint Solution Run
Click Run Button to view compiled output
4. Show products whose names contain the word "Table."
Code In Sql
-- Table Name : Products
-- Product_ID | Product_Name | Category | Price | Stock
-- ------------+ -------------+-------------+-------+-------
-- 1 | Laptop | Electronics | 55000 | 15
-- 2 | Mobile Phone | Electronics | 30000 | 30
-- 3 | Office Chair | Furniture | 7000 | 10
-- 4 | Coffee Maker | Appliances | 4000 | 20
-- 5 | Dining Table | Furniture | 15000 | 5
-- Your Query Here
Hint Solution Run
Click Run Button to view compiled output
5. Calculate the average price for each category of products.
Code In Sql
-- Table Name : Products
-- Product_ID | Product_Name | Category | Price | Stock
-- ------------+ -------------+-------------+-------+-------
-- 1 | Laptop | Electronics | 55000 | 15
-- 2 | Mobile Phone | Electronics | 30000 | 30
-- 3 | Office Chair | Furniture | 7000 | 10
-- 4 | Coffee Maker | Appliances | 4000 | 20
-- 5 | Dining Table | Furniture | 15000 | 5
-- Your Query Here
Hint Solution Run
Click Run Button to view compiled output
6. List products with stock levels between 10 and 25.
Code In Sql
-- Table Name : Products
-- Product_ID | Product_Name | Category | Price | Stock
-- ------------+ -------------+-------------+-------+-------
-- 1 | Laptop | Electronics | 55000 | 15
-- 2 | Mobile Phone | Electronics | 30000 | 30
-- 3 | Office Chair | Furniture | 7000 | 10
-- 4 | Coffee Maker | Appliances | 4000 | 20
-- 5 | Dining Table | Furniture | 15000 | 5
-- Your Query Here
Hint Solution Run
Click Run Button to view compiled output
7. Retrieve products with a price above 10000 and stock greater than 10.
Code In Sql
-- Table Name : Products
-- Product_ID | Product_Name | Category | Price | Stock
-- ------------+ -------------+-------------+-------+-------
-- 1 | Laptop | Electronics | 55000 | 15
-- 2 | Mobile Phone | Electronics | 30000 | 30
-- 3 | Office Chair | Furniture | 7000 | 10
-- 4 | Coffee Maker | Appliances | 4000 | 20
-- 5 | Dining Table | Furniture | 15000 | 5
-- Your Query Here
Hint Solution Run
Click Run Button to view compiled output
8. Show categories with more than one product.
Code In Sql
-- Table Name : Products
-- Product_ID | Product_Name | Category | Price | Stock
-- ------------+ -------------+-------------+-------+-------
-- 1 | Laptop | Electronics | 55000 | 15
-- 2 | Mobile Phone | Electronics | 30000 | 30
-- 3 | Office Chair | Furniture | 7000 | 10
-- 4 | Coffee Maker | Appliances | 4000 | 20
-- 5 | Dining Table | Furniture | 15000 | 5
-- Your Query Here
Hint Solution Run
Click Run Button to view compiled output
9. Count the number of products in each category.
Code In Sql
-- Table Name : Products
-- Product_ID | Product_Name | Category | Price | Stock
-- ------------+ -------------+-------------+-------+-------
-- 1 | Laptop | Electronics | 55000 | 15
-- 2 | Mobile Phone | Electronics | 30000 | 30
-- 3 | Office Chair | Furniture | 7000 | 10
-- 4 | Coffee Maker | Appliances | 4000 | 20
-- 5 | Dining Table | Furniture | 15000 | 5
-- Your Query Here
Hint Solution Run
Click Run Button to view compiled output
10. Retrieve the highest-priced product in each category.
Code In Sql
-- Table Name : Products
-- Product_ID | Product_Name | Category | Price | Stock
-- ------------+ -------------+-------------+-------+-------
-- 1 | Laptop | Electronics | 55000 | 15
-- 2 | Mobile Phone | Electronics | 30000 | 30
-- 3 | Office Chair | Furniture | 7000 | 10
-- 4 | Coffee Maker | Appliances | 4000 | 20
-- 5 | Dining Table | Furniture | 15000 | 5
-- Your Query Here
Hint Solution Run
Click Run Button to view compiled output