-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSuperStoreOrdersAnalysis.sql
More file actions
103 lines (102 loc) · 2.5 KB
/
Copy pathSuperStoreOrdersAnalysis.sql
File metadata and controls
103 lines (102 loc) · 2.5 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
--- overview of supestore dataset
SELECT
COUNT(order_id) AS Total_orders,
COUNT(DISTINCT country) AS Total_countries,
COUNT(DISTINCT product_name) AS Total_prodcuts,
COUNT(DISTINCT category) AS Total_categories,
COUNT(DISTINCT sub_category) AS Total_subcategories,
COUNT(DISTINCT year) AS Total_years,
SUM(sales) AS Total_sales,
SUM(quantity) AS Total_quantity_sold,
AVG(profit) AS Avg_profit,
AVG(discount) AS Total_discount
FROM dbo.SuperStoreOrders;
--- Sales performance Analysis---
SELECT TOP 10
product_name,
category,
SUM(sales) AS Total_sales,
SUM(quantity) AS Total_quantity_sold
FROM dbo.SuperStoreOrders
GROUP BY
product_name, category
ORDER BY
SUM(sales) DESC;
--- Sales Trends over the years---
SELECT
year,
SUM(sales) AS Total_sales_year
FROM dbo.SuperStoreOrders
GROUP BY year
ORDER BY SUM(sales) DESC;
--- Customer segmentation based on purchasing behaviour---
SELECT
segment,
COUNT(DISTINCT customer_name) AS Total_customers,
SUM(sales) AS Total_sales
FROM dbo.SuperStoreOrders
GROUP BY segment
ORDER BY SUM(sales) DESC;
---shipping and order analysis---
SELECT
ship_mode,
AVG(shipping_cost) AS Avg_shipping_cost,
AVG(profit) AS Avg_profit
FROM dbo.SuperStoreOrders
GROUP BY ship_mode
ORDER BY AVG(profit);
---Time analysis---
SELECT
ship_mode,
AVG(DATEDIFF(DAY, TRY_CAST( order_date AS DATE),TRY_CAST( ship_date AS DATE))) AS Avg_time_gap
FROM dbo.SuperStoreOrders
GROUP BY ship_mode
--- profitability and cost analysis---
SELECT
product_name,
category,
sub_category,
AVG(profit) AS Avg_profit,
AVG(discount) AS Avg_discount
FROM dbo.SuperStoreOrders
GROUP BY
product_name,
category,
sub_category
ORDER BY AVG(profit) DESC;
---Global sales and quantity of product overview---
SELECT
country,
SUM(sales) AS Total_sales,
SUM(quantity) AS Total_quantity
FROM dbo.SuperStoreOrders
GROUP BY country
ORDER BY SUM(sales) DESC;
---Most sold product per country---
SELECT
country,
product_name,
SUM(quantity) AS Total_quantity_sold,
SUM(sales) AS Total_sales
FROM dbo.SuperStoreOrders
GROUP BY
product_name,
country
ORDER BY SUM(sales) DESC;
---state level category analysis and exploration
SELECT
state,
product_name,
category,
SUM(quantity) AS Total_quantity_sold
FROM dbo.SuperStoreOrders
GROUP BY product_name, category,state
ORDER BY SUM(quantity) DESC;
---Regional subcategory analysis---
SELECT
region,
sub_category,
SUM(quantity) AS Total_quantity_sold
FROM dbo.SuperStoreOrders
GROUP BY region, sub_category
ORDER BY SUM(quantity) DESC;