-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSQL10feb2.sql
More file actions
225 lines (115 loc) · 5.67 KB
/
SQL10feb2.sql
File metadata and controls
225 lines (115 loc) · 5.67 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
USE PRODUCT_DB;
Create tables below and perform the queries.
in table give proper constraints.
1. Table 1 : Trains (
train_id (not blank),
train_name (not blank),
source (not blank),
destination (not blank),
departure_time (not blank),
arrival_time (not blank),
distance_km (should be > 0)
2. Table 2 : Passengers (
passenger_id,
name (not blank),
age should be(age > 0),
gender shoul be ('M', 'F')),
city
3. Table 3 : Reservations (
res_id ,
passenger_ID,
train_id ,
travel_date (not blank),
class should be ('Sleeper', 'AC1', 'AC2', 'AC3')),
fare (fare >= 0),
status should be('Confirmed', 'Waiting', 'Cancelled'))
--List all trains running from Delhi as source station.
--Find all passengers who are above 40 years of age.
--Get the total number of reservations made.
--Count how many reservations are in 'Confirmed' status.
--Show the average fare paid for each train.
--List reservations ordered by fare in descending order.
--Find passengers who booked AC classes (AC2, AC3).
--Get total revenue collected per train (only Confirmed reservations).
--Find the train with the maximum distance_km.
--Show number of male and female passengers.
--Get the passenger names who have booked tickets in Sleeper class.
--Find total number of reservations made from each city (JOIN with Passengers).
--Show train name and total passengers booked for it, ordered by passenger count descending.
--Find the average age of passengers who booked 'Confirmed' tickets.
--Display travel_date and number of reservations made on that date.
Show all reservations where fare is greater than 1000.
List all passengers who live in Delhi or Mumbai.
Show all trains whose distance is more than 1200 km.
Find reservations which are not "Cancelled".
Show the details of trains that have "Exp" in their name.
List all passengers ordered by their age in descending order.
Display reservations sorted by travel_date (earliest first).
Find all trains ordered by distance (longest route first).
Show passengers ordered by name alphabetically.
List reservations ordered by class and then by fare.
Count how many passengers are from each city.
Find the total fare collected from all Confirmed reservations.
Show the minimum, maximum, and average age of passengers.
Find the highest fare paid in Sleeper class.
Get the average fare per travel_date.
Show each class and the total number of reservations in it.
Find trains that have more than 1 reservation.
List cities where more than 1 passenger lives.
Show gender-wise average age of passengers.
Find passengers who booked more than 1 ticket.
Show passenger name, train name, and fare for each reservation.
List all passengers and the train name they booked (if any).
Show all trains and the number of passengers booked in each.
Find all passengers who booked Rajdhani Exp.
List passenger names with their travel_date and status.
Find the top 2 highest fare reservations.
Find the train with the lowest average fare.
Show the train(s) where total distance travelled by all passengers > 1000 km.
Find passengers whose reservation status is "Waiting".
Show the passenger(s) who paid the maximum fare overall.
Show all passengers whose age is between 20 and 40.
Find trains that start from Kolkata or Chennai.
Show all reservations made after 2025-09-05.
Display passengers whose name starts with 'A'.
List passengers whose city is NOT Delhi.
Show the 3 youngest passengers.
Show the 2 longest-distance trains.
Display the 5 most expensive reservations (highest fare).
List trains in alphabetical order of train_name.
Show passengers sorted by age (youngest first).
Find the average fare of all reservations.
Count the total number of male passengers.
Show the maximum distance among all trains.
Find the total number of Sleeper class reservations.
Find the total fare paid by passengers from Mumbai.
Count the number of reservations per status (Confirmed/Waiting/Cancelled).
Find the total number of passengers per gender.
Show the average fare for each class.
Display the number of trains starting from each source city.
Show total reservations grouped by travel_date.
Show passenger name, city, and train_name they booked.
List all reservations with passenger name and status.
Show train_name and number of confirmed passengers on it.
Display all passengers with train_name (if booked, else show NULL).
Find which passengers booked Garib Rath train.
Show train_id and total fare collected, but only where fare > 1000.
List source cities that have more than 1 train.
Find passengers grouped by city where count > 1.
Show classes that earned more than 2000 fare in total.
List trains that have at least 2 passengers booked.
Find the passenger(s) with the highest age.
Show the train(s) with the shortest distance.
Find the reservation(s) with the lowest fare.
List passengers who paid above the average fare.
Find trains whose distance is above the average train distance.
Show all reservations in September 2025.
Find the earliest travel_date booked.
Find the latest travel_date booked.
Count how many reservations are made per day.
List passengers who booked tickets on the same date.
Show passenger name, train_name, and distance travelled.
Find the city that contributed the highest number of passengers.
Display each train and its average fare (confirmed only).
Show passengers who booked tickets in more than one class.
Find train_name with maximum number of reservations