0% found this document useful (0 votes)
31 views

SQL Practice Statements

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

SQL Practice Statements

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

SQL Practice Statements

sale_id product_id quantity_sold sale_date total_price

1 101 5 2024-01-01 2500.00

2 102 3 2024-01-02 900.00

3 103 2 2024-01-02 60.00

4 104 4 2024-01-03 80.00

5 105 6 2024-01-03 90.00

1. Retrieve all columns from the Sales table.


2. Retrieve the product_name and unit_price from the Products table.
3. Retrieve the sale_id and sale_date from the Sales table.
4. Filter the Sales table to show only sales with a total_price greater than $100.
5. Filter the Products table to show only products in the 'Electronics' category.
6. Retrieve the sale_id and total_price from the Sales table for sales made on January 3, 2024.
7. Retrieve the product_id and product_name from the Products table for products with a
unit_price greater than $100.
8. Calculate the total revenue generated from all sales in the Sales table.
9. Calculate the average unit_price of products in the Products table.
10. Calculate the total quantity_sold from the Sales table.
11. Retrieve the sale_id, product_id, and total_price from the Sales table for sales with a
quantity_sold greater than 4.
12. Retrieve the product_name and unit_price from the Products table, ordering the results by
unit_price in descending order.
13. Retrieve the total_price of all sales, rounding the values to two decimal places.
14. Calculate the average total_price of sales in the Sales table.
15. Retrieve the sale_id and sale_date from the Sales table, formatting the sale_date as
'YYYY-MM-DD'.
16. Calculate the total revenue generated from sales of products in the 'Electronics' category.
17. Retrieve the product_name and unit_price from the Products table, filtering the unit_price
to show only values between $20 and $600.
18. Retrieve the product_name and category from the Products table, ordering the results by
category in ascending order.
19. Calculate the total quantity_sold of products in the 'Electronics' category.
20. Retrieve the product_name and total_price from the Sales table, calculating the total_price
as quantity_sold multiplied by unit_price.
21.Calculate the total revenue generated from sales for each product category.
22.Find the product category with the highest average unit price.
23.Identify products with total sales exceeding 30.
24. Count the number of sales made in each month.
25. Determine the average quantity sold for products with a unit price greater than $100.
26. Retrieve the product name and total sales revenue for each product.
27. List all sales along with the corresponding product names.
28. Retrieve the product name and total sales revenue for each product.
29. Rank products based on total sales revenue.
30. Calculate the running total revenue for each product category.
31.Identify sales where the quantity sold is greater than the average quantity sold.

VIEWS , JOINS and Clauses


1.Write a query to create a view named Total_Sales that displays the total sales amount for
each product along with their names and categories.
2.Retrieve the product details (name, category, unit price) for products that have a quantity
sold greater than the average quantity sold across all products.
3.Explain the significance of indexing in SQL databases and provide an example scenario
where indexing could significantly improve query performance in the given schema.
4. Add a foreign key constraint to the Sales table that references the product_id column in the
Products table.
5. Create a view named Top_Products that lists the top 3 products based on the total quantity
sold.
6. Create a view named Product_Sales_Info that displays product details along with the total
number of sales made for each product.

7. Create a query that lists the product names along with their corresponding sales count.
8. Write a query to find all sales where the total price is greater than the average total price of
all sales.

You might also like