-
Notifications
You must be signed in to change notification settings - Fork 0
/
queries.sql
38 lines (25 loc) · 1.33 KB
/
queries.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
-- Find the average fare for each route
SELECT r.RouteID, AVG(r.Fare) AS AverageFare
FROM Routes r
GROUP BY r.RouteID;
-- Find the total number of trains scheduled at each station
SELECT Stations.StationName, COUNT(*) AS TotalTrains
FROM Stations
INNER JOIN TrainSchedule ON Stations.StationID = TrainSchedule.StationID
GROUP BY Stations.StationName;
-- Retrieve all passengers who have made a complaint
SELECT Passengers.PassengerID, Passengers.PassengerName, Complaints.ComplaintType
FROM Passengers
INNER JOIN Complaints ON Passengers.PassengerID = Complaints.PassengerID;
-- Passengers who have a positive token balance
SELECT Passengers.PassengerID, Passengers.PassengerName, Passengers.Age, Passengers.Gender, Passengers.ContactNumber, Passengers.Email, Passengers.PaymentMethod, Token.TokenBalance
FROM Passengers
INNER JOIN Token ON Passengers.PassengerID = Token.PassengerID
WHERE Token.TokenBalance > 0;
-- Retrieves the details of passengers who have traveled on a specific train
SELECT Passengers.PassengerID, Passengers.PassengerName, Passengers.Age, Passengers.Gender, Passengers.ContactNumber, Passengers.Email,
Trains.TrainID, Trains.TrainName
FROM Passengers
INNER JOIN TrainSchedule ON Passengers.PassengerID = TrainSchedule.PassengerID
INNER JOIN Trains ON TrainSchedule.TrainID = Trains.TrainID
WHERE Trains.TrainID = 12345;