-
Notifications
You must be signed in to change notification settings - Fork 0
/
SQLQuery2 - AirlineSatisfaction.sql
229 lines (212 loc) · 7.59 KB
/
SQLQuery2 - AirlineSatisfaction.sql
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
226
227
228
229
/****** Script for SelectTopNRows command from SSMS ******/
SELECT TOP (1000) [Column 0]
,[id]
,[Gender]
,[Customer Type]
,[Age]
,[Type of Travel]
,[Class]
,[Flight Distance]
,[Inflight wifi service]
,[Departure Arrival time convenient]
,[Ease of Online booking]
,[Gate location]
,[Food and drink]
,[Online boarding]
,[Seat comfort]
,[Inflight entertainment]
,[On-board service]
,[Leg room service]
,[Baggage handling]
,[Checkin service]
,[Inflight service]
,[Cleanliness]
,[Departure Delay in Minutes]
,[Arrival Delay in Minutes]
,[satisfaction]
FROM [airline_satisfaction1].[dbo].[airline_dataset]
-- Total the dataset rows
SELECT COUNT(*) FROM [airline_satisfaction1].[dbo].[airline_dataset]
-- Total of the passengers
SELECT COUNT(DISTINCT ID) FROM [airline_satisfaction1].[dbo].[airline_dataset]
-- Total passengers based on gender
SELECT SUM(CASE WHEN Gender = 'male' THEN 1 ELSE 0 END) as Male_count,
SUM(CASE WHEN Gender = 'Female' THEN 1 ELSE 0 END) as Female_count
FROM [airline_satisfaction1].[dbo].[airline_dataset]
-- Total passengers based on satisfaction
SELECT SUM(CASE WHEN satisfaction = 'satisfied' THEN 1 ELSE 0 END) as satisfied_count,
SUM(CASE WHEN satisfaction = 'neutral or dissatisfied' THEN 1 ELSE 0 END) as neutral_or_dissatisfied_count
FROM [airline_satisfaction1].[dbo].[airline_dataset]
-- Total passengers of each travel type
SELECT SUM(CASE WHEN "Type of travel" = 'Business travel' THEN 1 ELSE 0 END) as total_business_travel,
SUM(CASE WHEN "Type of travel" = 'Personal Travel' THEN 1 ELSE 0 END) as total_personal_travel
FROM [airline_satisfaction1].[dbo].[airline_dataset]
-- Total passengers of each passenger class
SELECT SUM(CASE WHEN Class = 'Eco' THEN 1 ELSE 0 END) as total_eco,
SUM(CASE WHEN Class = 'Eco Plus' THEN 1 ELSE 0 END) as total_eco_plus,
SUM(CASE WHEN Class = 'Business' THEN 1 ELSE 0 END) as total_business
FROM [airline_satisfaction1].[dbo].[airline_dataset]
-- Total passengers of each customer type
SELECT SUM(CASE WHEN "Customer type" = 'disloyal Customer' THEN 1 ELSE 0 END) as total_disloyal,
SUM(CASE WHEN "Customer type" = 'Loyal Customer' THEN 1 ELSE 0 END) as total_loyal
FROM [airline_satisfaction1].[dbo].[airline_dataset]
-- Total passengers & Average arrival delay with age less than 20
SELECT Class,
"Customer Type",
"Type of travel",
Gender,
satisfaction,
ROUND(AVG(CAST("Arrival Delay in Minutes" as float)),2) as avg_arrival_delay,
COUNT(ID) as total_passengers
FROM [airline_satisfaction1].[dbo].[airline_dataset]
WHERE Age < 20
GROUP BY Class,
"Customer Type",
"Type of travel",
Gender,
satisfaction
ORDER BY total_passengers DESC
-- Total passengers & Average arrival delay with age between 20 until 30
SELECT Class,
"Customer Type",
"Type of travel",
Gender,
satisfaction,
ROUND(AVG(CAST("Arrival Delay in Minutes" as float)),2) as avg_arrival_delay,
COUNT(ID) as total_passengers
FROM [airline_satisfaction1].[dbo].[airline_dataset]
WHERE Age BETWEEN 20 AND 30
GROUP BY Class,
"Customer Type",
"Type of travel",
Gender,
satisfaction
ORDER BY total_passengers DESC
-- Total passengers & Average arrival delay with age greater than 30
SELECT Class,
"Customer Type",
"Type of travel",
Gender,
satisfaction,
ROUND(AVG(CAST("Arrival Delay in Minutes" as float)),2) as avg_arrival_delay,
COUNT(ID) as total_passengers
FROM [airline_satisfaction1].[dbo].[airline_dataset]
WHERE Age > 30
GROUP BY Class,
"Customer Type",
"Type of travel",
Gender,
satisfaction
ORDER BY total_passengers DESC
-- Total passengers & Average departure delay with age less than 20
SELECT Class,
"Customer Type",
"Type of travel",
Gender,
satisfaction,
ROUND(AVG(CAST("Departure Delay in Minutes" as float)),2) as avg_departure_delay,
COUNT(ID) as total_passengers
FROM [airline_satisfaction1].[dbo].[airline_dataset]
WHERE Age < 20
GROUP BY Class,
"Customer Type",
"Type of travel",
Gender,
satisfaction
ORDER BY total_passengers DESC
-- Total passengers & Average departure delay with age between 20 until 30
SELECT Class,
"Customer Type",
"Type of travel",
Gender,
satisfaction,
ROUND(AVG(CAST("Departure Delay in Minutes" as float)),2) as avg_departure_delay,
COUNT(ID) as total_passengers
FROM [airline_satisfaction1].[dbo].[airline_dataset]
WHERE Age BETWEEN 20 AND 30
GROUP BY Class,
"Customer Type",
"Type of travel",
Gender,
satisfaction
ORDER BY total_passengers DESC
-- Total passengers & Average departure delay with age greater than 30
SELECT Class,
"Customer Type",
"Type of travel",
Gender,
satisfaction,
ROUND(AVG(CAST("Departure Delay in Minutes" as float)),2) as avg_departure_delay,
COUNT(ID) as total_passengers
FROM [airline_satisfaction1].[dbo].[airline_dataset]
WHERE Age > 30
GROUP BY Class,
"Customer Type",
"Type of travel",
Gender,
satisfaction
ORDER BY total_passengers DESC
-- Total passengers & Average flight distance with age less than 20
SELECT Class,
"Customer Type",
"Type of travel",
Gender,
satisfaction,
ROUND(AVG(CAST("Flight Distance" as float)),2) as avg_flight_distance,
COUNT(ID) as total_passengers
FROM [airline_satisfaction1].[dbo].[airline_dataset]
WHERE Age < 20
GROUP BY Class,
"Customer Type",
"Type of travel",
Gender,
satisfaction
ORDER BY total_passengers DESC
-- Total passengers & Average flight distance with age between 20 until 30
SELECT Class,
"Customer Type",
"Type of travel",
Gender,
satisfaction,
ROUND(AVG(CAST("Flight Distance" as float)),2) as avg_flight_distance,
COUNT(ID) as total_passengers
FROM [airline_satisfaction1].[dbo].[airline_dataset]
WHERE Age BETWEEN 20 AND 30
GROUP BY Class,
"Customer Type",
"Type of travel",
Gender,
satisfaction
ORDER BY total_passengers DESC
-- Total passengers & Average flight distance with age greater than 30
SELECT Class,
"Customer Type",
"Type of travel",
Gender,
satisfaction,
ROUND(AVG(CAST("Flight Distance" as float)),2) as avg_flight_distance,
COUNT(ID) as total_passengers
FROM [airline_satisfaction1].[dbo].[airline_dataset]
WHERE Age > 30
GROUP BY Class,
"Customer Type",
"Type of travel",
Gender,
satisfaction
ORDER BY total_passengers DESC
-- Flight rate service by passengers
SELECT AVG(CAST("Inflight wifi service" as tinyint)) as avg_inflightwifi,
AVG(CAST("Departure arrival time convenient" as tinyint)) as avg_timeconvenient,
AVG(CAST("Ease of online booking" as tinyint)) as avg_easebooking,
AVG(CAST("Gate location" as tinyint)) as avg_gatelocation,
AVG(CAST("Food and drink" as tinyint)) as avg_foodndrink,
AVG(CAST("Online boarding" as tinyint)) as avg_onlineboarding,
AVG(CAST("Seat comfort" as tinyint)) as avg_seatcomfort,
AVG(CAST("Inflight entertainment" as tinyint)) as avg_inflightent,
AVG(CAST("On-board service" as tinyint)) as avg_onboard,
AVG(CAST("Leg room service" as tinyint)) as avg_legroom,
AVG(CAST("Baggage Handling" as tinyint)) as avg_baggagehandling,
AVG(CAST("Checkin service" as tinyint)) as avg_checkinservice,
AVG(CAST("Inflight service" as tinyint)) as avg_inflightservice,
AVG(CAST("Cleanliness" as tinyint)) as avg_cleanliness
FROM [airline_satisfaction1].[dbo].[airline_dataset]