-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHotelRevenueAnalysis.sql
More file actions
225 lines (155 loc) · 4.83 KB
/
HotelRevenueAnalysis.sql
File metadata and controls
225 lines (155 loc) · 4.83 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
/*
Project:
Develop a Database to Analyze and Visulaize Hotel Booking Data
Task: Build a Data Story or Dashboard using Power BI to present to Stakeholder for business decisions
1. Is our hotel revenue growing by year? ( We have two hotel types, we would like to analyze revenue by hotel types)
2. Should we increase our parking lot size? ( To understand if there's a trend with guests with personal cars)
3. What trends can we see in the data ? ( Focusing on Average Daily Rates and Guests to explore seasonability)
Pipelines:
Step 1 : Build a Database, import data
Step 2 : Develop the SQL Query
Step 3 : Connect Database to Power BI
Step 4: Visualize
Step 5: Summarize our findings
Step 6: Publish Dashboard to Service
*/
-- Data Exploration
-- Let's see all tables at once
Select * from dbo.Hotel2018
Select * from dbo.Hotel2019
Select * from dbo.Hotel2020
-- Let's unify these dataset by using UNION
Select * from dbo.Hotel2018
union
Select * from dbo.Hotel2019
union
Select * from dbo.Hotel2020
-- Exploratory Data Analysis
-- We will create a TEMP TABLE using the select statements from above
WITH hotels as
(
Select * from dbo.Hotel2018
union
Select * from dbo.Hotel2019
union
Select * from dbo.Hotel2020
)
Select * from hotels
-- Question: Is the hotel revenue growing by year?
-- We will create a DERIVED COLUMN display that
-- We will add the two columns Stays_in_Week_nights and Stays_in_Weekend_nights
WITH hotels as
(
Select * from dbo.Hotel2018
union
Select * from dbo.Hotel2019
union
Select * from dbo.Hotel2020
)
Select stays_in_week_nights + stays_in_weekend_nights from hotels
-- Let's multiply this by the Average Daily Rate for the hotel and ALIAS it as REVENUE
WITH hotels as
(
Select * from dbo.Hotel2018
union
Select * from dbo.Hotel2019
union
Select * from dbo.Hotel2020
)
Select (stays_in_week_nights + stays_in_weekend_nights) *adr AS Revenue from hotels
-- Let's see if revenue is increasing by year by using the Arrival Date Year
WITH hotels as
(
Select * from dbo.Hotel2018
union
Select * from dbo.Hotel2019
union
Select * from dbo.Hotel2020
)
Select
arrival_date_year,
(stays_in_week_nights + stays_in_weekend_nights) *adr AS Revenue from hotels
-- Let's GROUP BY and SUM by YEAR
WITH hotels as
(
Select * from dbo.Hotel2018
union
Select * from dbo.Hotel2019
union
Select * from dbo.Hotel2020
)
Select
arrival_date_year,
SUM((stays_in_week_nights + stays_in_weekend_nights) *adr) AS Revenue from hotels
GROUP BY arrival_date_year
-- We can see that our revenue is indeed growing by year
-- Let's break this down by Hotel Type as per Business question
WITH hotels as
(
Select * from dbo.Hotel2018
union
Select * from dbo.Hotel2019
union
Select * from dbo.Hotel2020
)
Select
arrival_date_year,
hotel,
SUM((stays_in_week_nights + stays_in_weekend_nights) *adr) AS Revenue from hotels
GROUP BY arrival_date_year,hotel
--LETS ROUND OUR DECIMALS FOR EASY READABILITY
WITH hotels as
(
Select * from dbo.Hotel2018
union
Select * from dbo.Hotel2019
union
Select * from dbo.Hotel2020
)
Select
arrival_date_year,
hotel,
ROUND(SUM((stays_in_week_nights + stays_in_weekend_nights) *adr),2) AS Revenue from hotels
GROUP BY arrival_date_year,hotel
-- Let's JOIN this TEMP TABLE (hotels) with our tables
WITH hotels as
(
Select * from dbo.Hotel2018
union
Select * from dbo.Hotel2019
union
Select * from dbo.Hotel2020
)
Select * from hotels
JOIN dbo.market_segment
on hotels.market_segment = market_segment.market_segment -- We joined the Hotel DB/market_segment column = market_segment table /market_segment column
-- If we use LEFT JOIN, it will bring all the data irregardless if there's a match or not.
-- The LEFT Table is preserved
WITH hotels as
(
Select * from dbo.Hotel2018
union
Select * from dbo.Hotel2019
union
Select * from dbo.Hotel2020
)
Select * from hotels
LEFT JOIN dbo.market_segment
on hotels.market_segment = market_segment.market_segment -- We joined the Hotel DB/market_segment column = market_segment table /market_segment column
-- LEFT JOIN on Meal_cost table as well
WITH hotels as
(
Select * from dbo.Hotel2018
union
Select * from dbo.Hotel2019
union
Select * from dbo.Hotel2020
)
Select * from hotels
LEFT JOIN
dbo.market_segment
on hotels.market_segment = market_segment.market_segment
LEFT JOIN
dbo.meal_cost
on meal_cost.meal = hotels.meal -- Table/Column
-- Let's take this query to Power BI