-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path1-5 stored procedures.sql
71 lines (61 loc) · 2.06 KB
/
1-5 stored procedures.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
# Given passenger ID and date/type of trip selected, assign passenger to a flight ID that has
# open seats for that trip
# assume 10 is ticket price
DELIMITER //
CREATE PROCEDURE assignFlight(IN user_email VARCHAR(45), IN flightNum int)
BEGIN
insert into bookings values(flightNum,user_email,now());
update users set credit = credit+10 where user_email=`Primary Email`;
END //
DELIMITER ;
# • Given flight number, extract all the filled seats of the flight.
DELIMITER //
CREATE PROCEDURE extractFilledSeats(IN flightNumber int )
BEGIN
select * from ticket where Bookings_Flights_idFlights= flightNumber;
END //
DELIMITER ;
# • Given the date, then extract the flight available.
DELIMITER //
CREATE PROCEDURE searchAvailableFlight(IN date date )
BEGIN
select * from flights where date(`Departure Time`)=date;
END //
DELIMITER ;
# Given selected locations, list Departure city, arrival city or multi city.
DELIMITER //
CREATE PROCEDURE searchLocation(IN cityName varchar(45) )
BEGIN
select * from airports where City=cityName;
END //
DELIMITER ;
# Select number of passengers
DELIMITER //
CREATE PROCEDURE passengersNum(IN flight int )
BEGIN
select count(*) from ticket where Bookings_Flights_idFlights=flight;
END //
DELIMITER ;
# Select number of passengers
DELIMITER //
CREATE PROCEDURE passengersNum(IN flight int )
BEGIN
select count(*) from ticket where Bookings_Flights_idFlights=flight;
END //
DELIMITER ;
# Given passengers ID, extract award credit, and list miles that you earn.
DELIMITER //
CREATE PROCEDURE passengersNum(IN email varchar(30) )
BEGIN
select credit from users where `Primary Email` = email;
END //
DELIMITER ;
# Given departure city and arrival city, and date, then extract all the flight status on that day
# Given check status, then extract flight numbers, departure time, arrival time, departure city,
# arrival city, terminal number, gate number.
DELIMITER //
CREATE PROCEDURE extract(IN status varchar(30) )
BEGIN
select * from aircraft where Status=status;
END //
DELIMITER ;