-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlayoffs.sql
More file actions
48 lines (43 loc) · 1.14 KB
/
Copy pathlayoffs.sql
File metadata and controls
48 lines (43 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
-- layoffs.sql
-- Comprehensive Sales Analysis Queries
-- 1. Total revenue and total quantity sold by region
SELECT
Region,
SUM(Sales) AS Total_Revenue,
SUM(Quantity) AS Total_Quantity
FROM sales_data
GROUP BY Region
ORDER BY Total_Revenue DESC;
-- 2. Top 5 best-selling products
SELECT
Product,
SUM(Quantity) AS Total_Quantity_Sold,
SUM(Sales) AS Total_Revenue
FROM sales_data
GROUP BY Product
ORDER BY Total_Quantity_Sold DESC
LIMIT 5;
-- 3. Monthly sales trends for each category
SELECT
DATE_FORMAT(OrderDate, '%Y-%m') AS Month,
Category,
SUM(Sales) AS Total_Revenue,
SUM(Quantity) AS Total_Quantity
FROM sales_data
GROUP BY Month, Category
ORDER BY Month ASC, Category ASC;
-- 4. Average order value by region
SELECT
Region,
AVG(Sales/Quantity) AS Avg_Order_Value
FROM sales_data
GROUP BY Region
ORDER BY Avg_Order_Value DESC;
-- 5. Percentage contribution of each region to total revenue
SELECT
Region,
SUM(Sales) AS Region_Revenue,
ROUND(SUM(Sales)/ (SELECT SUM(Sales) FROM sales_data) * 100, 2) AS Revenue_Percentage
FROM sales_data
GROUP BY Region
ORDER BY Revenue_Percentage DESC;