-
Notifications
You must be signed in to change notification settings - Fork 0
/
Planes.sql
122 lines (107 loc) · 5.59 KB
/
Planes.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
-- QUERRY to give the flight passengers that fly in same flights
SELECT DISTINCT B.Passenger_Name, B.Passenger_ID, A.Flight_ID , A.Departure_Airport, A.Arival_Airport, A.Flight_Date , A.Flight_Time
FROM FlightCompany.Passenger B
JOIN FlightCompany.Flights A ON B.Passenger_Flight_ID = A.Flight_ID
ORDER BY A.Flight_ID DESC;
-- QUERRY to give the flight passengers that fly in same flights (for spesific flight)
SELECT DISTINCT B.Passenger_Name, B.Passenger_ID, A.Flight_ID , A.Departure_Airport, A.Arival_Airport, A.Flight_Date , A.Flight_Time
FROM FlightCompany.Passenger B
JOIN FlightCompany.Flights A ON B.Passenger_Flight_ID = A.Flight_ID AND A.Flight_ID LIKE '105'
ORDER BY A.Flight_ID DESC;
-- Querry that gives the flight employee flying the same flight
SELECT DISTINCT B.Employee_ID, B.Employee_Name, B.Job_Title , A.Flight_ID , A.Departure_Airport, A.Arival_Airport, A.Flight_Date , A.Flight_Time , C.Aircraft_Type
FROM FlightCompany.Employee B
JOIN FlightCompany.Flights A ON B.Attending_Flights = A.Flight_ID
JOIN FlightCompany.Plane C ON C.Flights = A.Flight_ID
ORDER BY A.Flight_ID DESC;
-- Querry that gives the flight employee flying the same flight (for spesific flight)
SELECT DISTINCT B.Employee_ID, B.Employee_Name, B.Job_Title , A.Flight_ID , A.Departure_Airport, A.Arival_Airport, A.Flight_Date , A.Flight_Time , C.Aircraft_Type
FROM FlightCompany.Employee B
JOIN FlightCompany.Flights A ON B.Attending_Flights = A.Flight_ID
JOIN FlightCompany.Plane C ON C.Flights = A.Flight_ID AND A.Flight_ID LIKE '105'
ORDER BY A.Flight_ID DESC;
-- View Tables for each emp flight in that plane
CREATE VIEW EMP_Airbus_A380 AS
SELECT B.Employee_ID, B.Employee_Name, B.Job_Title, AVG(B.Num_of_Flights) AS Avg_of_Flights, C.Aircraft_Type
FROM FlightCompany.Employee B, FlightCompany.Plane C
WHERE C.Aircraft_Type LIKE 'Airbus A380' AND C.Flights = B.Attending_Flights
GROUP BY C.Aircraft_Type, B.Employee_ID;
CREATE VIEW EMP_Boeing_737 AS
SELECT B.Employee_ID, B.Employee_Name, B.Job_Title, AVG(B.Num_of_Flights) AS Avg_of_Flights, C.Aircraft_Type
FROM FlightCompany.Employee B, FlightCompany.Plane C
WHERE C.Aircraft_Type LIKE 'Boeing 737' AND C.Flights = B.Attending_Flights
GROUP BY C.Aircraft_Type, B.Employee_ID;
CREATE VIEW EMP_Boeing_777 AS
SELECT B.Employee_ID, B.Employee_Name, B.Job_Title, AVG(B.Num_of_Flights) AS Avg_of_Flights, C.Aircraft_Type
FROM FlightCompany.Employee B, FlightCompany.Plane C
WHERE C.Aircraft_Type LIKE 'Boeing 777' AND C.Flights = B.Attending_Flights
GROUP BY C.Aircraft_Type, B.Employee_ID;
CREATE VIEW EMP_Airbus_A350 AS
SELECT B.Employee_ID, B.Employee_Name, B.Job_Title, AVG(B.Num_of_Flights) AS Avg_of_Flights, C.Aircraft_Type
FROM FlightCompany.Employee B, FlightCompany.Plane C
WHERE C.Aircraft_Type LIKE 'Airbus A350' AND C.Flights = B.Attending_Flights
GROUP BY C.Aircraft_Type, B.Employee_ID;
CREATE VIEW EMP_Airbus_A330 AS
SELECT B.Employee_ID, B.Employee_Name, B.Job_Title, AVG(B.Num_of_Flights) AS Avg_of_Flights, C.Aircraft_Type
FROM FlightCompany.Employee B, FlightCompany.Plane C
WHERE C.Aircraft_Type LIKE 'Airbus A330' AND C.Flights = B.Attending_Flights
GROUP BY C.Aircraft_Type, B.Employee_ID;
CREATE VIEW EMP_Boeing_787 AS
SELECT B.Employee_ID, B.Employee_Name, B.Job_Title, AVG(B.Num_of_Flights) AS Avg_of_Flights, C.Aircraft_Type
FROM FlightCompany.Employee B, FlightCompany.Plane C
WHERE C.Aircraft_Type LIKE 'Boeing 787' AND C.Flights = B.Attending_Flights
GROUP BY C.Aircraft_Type, B.Employee_ID;
CREATE VIEW EMP_Airbus_A319 AS
SELECT B.Employee_ID, B.Employee_Name, B.Job_Title, AVG(B.Num_of_Flights) AS Avg_of_Flights, C.Aircraft_Type
FROM FlightCompany.Employee B, FlightCompany.Plane C
WHERE C.Aircraft_Type LIKE 'Airbus A319' AND C.Flights = B.Attending_Flights
GROUP BY C.Aircraft_Type, B.Employee_ID;
CREATE VIEW EMP_Boeing_767 AS
SELECT B.Employee_ID, B.Employee_Name, B.Job_Title, AVG(B.Num_of_Flights) AS Avg_of_Flights, C.Aircraft_Type
FROM FlightCompany.Employee B, FlightCompany.Plane C
WHERE C.Aircraft_Type LIKE 'Boeing 767' AND C.Flights = B.Attending_Flights
GROUP BY C.Aircraft_Type, B.Employee_ID;
CREATE VIEW EMP_Boeing_747 AS
SELECT B.Employee_ID, B.Employee_Name, B.Job_Title, AVG(B.Num_of_Flights) AS Avg_of_Flights, C.Aircraft_Type
FROM FlightCompany.Employee B, FlightCompany.Plane C
WHERE C.Aircraft_Type LIKE 'Boeing 747' AND C.Flights = B.Attending_Flights
GROUP BY C.Aircraft_Type, B.Employee_ID;
CREATE VIEW EMP_Airbus_A320 AS
SELECT B.Employee_ID, B.Employee_Name, B.Job_Title, AVG(B.Num_of_Flights) AS Avg_of_Flights, C.Aircraft_Type
FROM FlightCompany.Employee B, FlightCompany.Plane C
WHERE C.Aircraft_Type LIKE 'Airbus A320' AND C.Flights = B.Attending_Flights
GROUP BY C.Aircraft_Type, B.Employee_ID;
-- Querry for planes avg flights acording to view tables
SELECT Planes, AVG(Flights)
FROM(
SELECT Aircraft_Type as Planes, Avg_of_Flights AS Flights
FROM emp_airbus_a319
UNION ALL
SELECT Aircraft_Type as Planes, Avg_of_Flights AS Flights
FROM emp_airbus_a320
UNION ALL
SELECT Aircraft_Type as Planes, Avg_of_Flights AS Flights
FROM emp_airbus_a330
UNION ALL
SELECT Aircraft_Type as Planes, Avg_of_Flights AS Flights
FROM emp_airbus_a350
UNION ALL
SELECT Aircraft_Type as Planes, Avg_of_Flights AS Flights
FROM emp_airbus_a380
UNION ALL
SELECT Aircraft_Type as Planes, Avg_of_Flights AS Flights
FROM emp_boeing_737
UNION ALL
SELECT Aircraft_Type as Planes, Avg_of_Flights AS Flights
FROM emp_boeing_747
UNION ALL
SELECT Aircraft_Type as Planes, Avg_of_Flights AS Flights
FROM emp_boeing_767
UNION ALL
SELECT Aircraft_Type as Planes, Avg_of_Flights AS Flights
FROM emp_boeing_777
UNION ALL
SELECT Aircraft_Type as Planes, Avg_of_Flights AS Flights
FROM emp_boeing_787
) A
Group by Planes;