SQL handouts

https://drive.google.com/file/d/1vyDyIKJP_83tlHc7uYOnVj0zS1C7HEEn/view?usp=sharing CSV Dataset https://drive.google.com/file/d/1EnaYj5VCTLIn9dVAOsIFlhNt9V1Vww_Z/view?usp=sharing 



1. Basic SELECT and WHERE

  1. Show all columns for orders from the North region.

  2. List Order_ID and Profit for orders where Profit is greater than 500.

  3. Retrieve all orders for Product_ID = 'P02'.

2. Calculations and Aliases

  1. Select Order_ID, Units_Sold, Unit_Price, and calculate Total_Amount as Units_Sold * Unit_Price.

  2. Find Revenue minus Cost for each order and show it as Calculated_Profit. Check if it matches the Profit column.

3. Filtering by Date and Numeric Ranges

  1. Select all orders placed on or after '2025-02-01'.

  2. Get orders where Units_Sold between 2 and 7 (inclusive).

4. GROUP BY and Aggregation

  1. Find total Revenue per Region.

  2. Find total Profit per Salesperson_ID.

  3. Find total Units_Sold for each Product_ID.

5. HAVING and Aggregated Filters

  1. Show Region and total Profit, but only for regions where total Profit > 1000.

  2. Show Salesperson_ID and total Revenue, but only those with Revenue > 3000.

6. ORDER BY and LIMIT/TOP

  1. List all orders ordered by Profit in descending order.

  2. Show the top 2 most profitable orders.

7. Joins (for later extension)

  1. Suppose you have a separate Product table (Product_ID, Product_Name). Write a query to show Order_ID, Product_Name, Units_Sold, and Profit.

  2. Suppose you have a Salesperson table (Salesperson_ID, Salesperson_Name, Region). Write a query to list Salesperson_Name and total Profit they generated.

Comments

Popular posts from this blog