8
8
* what is the total retail sales for each supplier?
9
9
10
10
QUERY:
11
- ![ image] ( https://user-images.githubusercontent.com/100838547/224489252-b4907cbb-ec04-449d-90fc-78a64874a903.png )
12
-
11
+ ``` sql
12
+ select supplier, sum (retailsales) as total_retail_sales
13
+ from project
14
+ group by supplier;
15
+ ```
13
16
RESULT:
14
17
15
18
![ supply] ( https://user-images.githubusercontent.com/100838547/224489292-87e0be9c-c732-4b43-8bf8-565bbc054124.png )
16
19
* what is the total retail sales for each combination of supplier and month
17
20
18
21
QUERY:
19
-
20
- ![ image] ( https://user-images.githubusercontent.com/100838547/224489809-dd3ed56a-9d34-4d49-af5f-f946ffc23ae9.png )
21
-
22
-
22
+ ``` sql
23
+ select supplier, year, month, sum (retailsales) as total_retail_sales
24
+ from project
25
+ group by supplier, year, month;
26
+ ```
23
27
RESULT:
24
28
25
29
![ S2] ( https://user-images.githubusercontent.com/100838547/224490032-fcd48f03-6b2a-4a76-a0f8-f4d74d25819d.png )
26
30
27
31
* what is the maximum warehouse sales for each item description?
28
32
29
33
QUERY:
30
- ![ image] ( https://user-images.githubusercontent.com/100838547/224490206-05217b28-21c9-4d4d-8285-40514de9a18e.png )
31
-
34
+ ``` sql
35
+ select itemdescription, max (retailsales) as max_warehouse_sales
36
+ from project
37
+ group by itemdescription;
38
+ ```
32
39
RESULT:
33
40
34
41
![ S3] ( https://user-images.githubusercontent.com/100838547/224490291-90dffa9b-fa4e-4514-8df8-5f2ffbb4cb28.png )
35
42
36
43
* what is the average retail transfer for each year
37
44
38
45
QUERY:
39
- ![ image] ( https://user-images.githubusercontent.com/100838547/224490403-6237613c-5cbb-49de-bed1-2c8238a72583.png )
46
+ ``` sql
47
+ select year, avg (retailtransfers) as avg_retail_transfers
48
+ from project
49
+ group by year;
50
+ ```
40
51
41
52
RESULT:
42
53
43
54
![ S4] ( https://user-images.githubusercontent.com/100838547/224490466-0d7f489f-88b2-4aad-8156-c5072dd131ca.png )
44
55
45
56
* for each item description, what is the difference between the maximum and minimum retail sales?
46
57
QUERY:
47
- ![ image] ( https://user-images.githubusercontent.com/100838547/224490673-9d03f8ac-6d80-4380-9798-eb72a39fb24f.png )
48
-
58
+ ``` sql
59
+ select itemdescription, max (retailsales) - min (retailsales) as diff_max_min_retail_sales
60
+ from project
61
+ group by itemdescription;
62
+ ```
49
63
RESULT:
50
64
51
65
![ S5] ( https://user-images.githubusercontent.com/100838547/224490734-631015ab-8936-4c4a-9c73-3e3a399d0b68.png )
52
66
53
67
* what is the total retail sales for each supplier, broken down by year and month
54
68
55
69
QUERY:
56
- ![ image] ( https://user-images.githubusercontent.com/100838547/224491141-5c06e507-4b74-44ab-8687-8aa280bbe7d1.png )
57
- RESULT:
70
+ ``` sql
71
+ select year, month, supplier,
72
+ sum (retailsales) over (partition by supplier, year, month) as total_retail_sales
73
+ from project;
74
+ ```
58
75
76
+ RESULT:
59
77
![ S6] ( https://user-images.githubusercontent.com/100838547/224491227-92c48a4c-6169-4b7e-9375-3d224715f18c.png )
60
78
61
79
* what is the running total of retail sales for each item type, order by month?
62
80
QUERY:
63
- ![ image] ( https://user-images.githubusercontent.com/100838547/224491440-96150a79-b1a3-4807-a64d-e34b52c60d14.png )
81
+ ``` sql
82
+ select year, month, itemtype,
83
+ sum (retailsales) over (partition by itemtype order by month) as running_total_retail_sales
84
+ from project;
85
+ ```
64
86
65
87
RESULT:
66
88
@@ -69,7 +91,11 @@ RESULT:
69
91
70
92
* what is the difference in retail sales between each month and the previous month, for each supplier and item type?
71
93
QUERY:
72
- ![ image] ( https://user-images.githubusercontent.com/100838547/224491732-f5aa07e3-cc20-430b-be2c-39378579a454.png )
94
+ ``` sql
95
+ select year, month, supplier, itemtype,
96
+ retailsales - lag(retailsales) over (partition by supplier, itemtype order by year, month) as diff_retail_sales
97
+ from project;
98
+ ```
73
99
74
100
RESULT:
75
101
0 commit comments