0% found this document useful (0 votes)
21 views

Airplane

Uploaded by

12030024
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

Airplane

Uploaded by

12030024
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

ER diagram

Mapping:
AIRPLANE
airplane_code model_numbe num_of_seats production_year
r
PK FK
AIRPLANE_MODEL
model_number company_name

PK
FLIGHT
flight_number airport_code arr_time dep_time

PK FK
AIRPORT
airport_code country airport_name

PK
EMPLOYEE
employee_ID Name salary hire_date role
PK
EMLOYNMENT
airport_code employee_ID
FK FK
JOURNEY
journey_ flight_ airplane_ journey number actual_ actual_
ID number code _date _of_ arr_ dep_
passenger time time
s
PK FK FK
SEAT
seat_number passenger_ID journey_ID
PK FK FK
PASSENGERS
passenger_I passenger_nam emai ag phone_numbe nationalit
D e l e r y

PK

SQL queries
Create database airport_;

Use airport_;

CREATE TABLE Journeys (


journey_id INT PRIMARY KEY,
journey_date DATE,
flight_number VARCHAR(10),
departing_airport_code VARCHAR(5),
arrival_airport_code VARCHAR(5),
actual_departure_time TIME,
actual_arrival_time TIME
);

CREATE TABLE Airports (


airport_code VARCHAR(5) PRIMARY KEY,
airport_name VARCHAR(100),
country VARCHAR(50)
);

CREATE TABLE Flights (


flight_number VARCHAR(10) PRIMARY KEY,
departing_airport_code VARCHAR(5),
arrival_airport_code VARCHAR(5),
scheduled_departure_time TIME,
scheduled_arrival_time TIME
);

CREATE TABLE Passengers (


passenger_id INT PRIMARY KEY,
journey_id INT,
nationality VARCHAR(50)
);

CREATE TABLE Airplanes (


airplane_code VARCHAR(10) PRIMARY KEY,
number_of_seats INT,
production_year INT,
airplane_company VARCHAR(50)
);

INSERT INTO Airports (airport_code, airport_name,


country) VALUES
('JFK', 'John F. Kennedy International Airport', 'USA'),
('CDG', 'Charles de Gaulle Airport', 'France'),
('LHR', 'Heathrow Airport', 'UK'),
('BEY', 'Beirut International Airport', 'Lebanon'),
('LAX', 'Los Angeles International Airport', 'USA');
INSERT INTO Flights (flight_number,
departing_airport_code, arrival_airport_code,
scheduled_departure_time, scheduled_arrival_time)
VALUES
('AF123', 'JFK', 'CDG', '08:00', '20:00'),
('BA456', 'LHR', 'CDG', '10:00', '12:30'),
('ME123', 'BEY', 'LHR', '14:00', '18:00'),
('ME124', 'JFK', 'BEY', '12:00', '22:00');

INSERT INTO Journeys (journey_id, journey_date,


flight_number, departing_airport_code,
arrival_airport_code, actual_departure_time,
actual_arrival_time) VALUES
(1, '2015-10-01', 'AF123', 'JFK', 'CDG', '08:05', '20:15'),
(2, '2015-10-11', 'BA456', 'LHR', 'CDG', '10:10', '12:40'),
(3, '2015-10-11', 'ME123', 'BEY', 'LHR', '14:10', '18:30'),
(4, '2015-10-15', 'ME124', 'JFK', 'BEY', '12:20', '22:50');
INSERT INTO Passengers (passenger_id, journey_id,
nationality) VALUES
(1, 1, 'USA'),
(2, 1, 'France'),
(3, 2, 'UK'),
(4, 2, 'France'),
(5, 3, 'Lebanon'),
(6, 3, 'UK'),
(7, 4, 'USA'),
(8, 4, 'Lebanon');

INSERT INTO Airplanes (airplane_code,


number_of_seats, production_year, airplane_company)
VALUES
('A320', 180, 2015, 'Airbus'),
('B737', 160, 2012, 'Boeing'),
('A380', 500, 2010, 'Airbus'),
('B747', 400, 2005, 'Boeing');
SELECT COUNT(*)
FROM Journeys
WHERE journey_date BETWEEN '2015-10-01' AND
'2015-10-31';

SELECT country, COUNT(*) AS total_airports


FROM Airports
GROUP BY country;

SELECT f.flight_number, d_airport.airport_name AS


departing_airport,
a_airport.airport_name AS arrival_airport,
f.scheduled_departure_time, f.scheduled_arrival_time
FROM Flights f
JOIN Airports d_airport ON f.departing_airport_code =
d_airport.airport_code
JOIN Airports a_airport ON f.arrival_airport_code =
a_airport.airport_code
WHERE a_airport.country = 'France';

SELECT COUNT(*)
FROM Passengers;

SELECT p.nationality, COUNT(*) AS total_passengers


FROM Passengers p
JOIN Journeys j ON p.journey_id = j.journey_id
WHERE j.journey_date BETWEEN '2015-10-11' AND
'2015-10-16'
AND j.flight_number = '227'
GROUP BY p.nationality;

SELECT j.journey_date, j.flight_number,


d_airport.airport_name AS departing_airport,
a_airport.airport_name AS arrival_airport,
j.actual_departure_time, j.actual_arrival_time
FROM Journeys j
JOIN Airports d_airport ON j.departing_airport_code =
d_airport.airport_code
JOIN Airports a_airport ON j.arrival_airport_code =
a_airport.airport_code
WHERE d_airport.airport_name = 'Beirut International
Airport'
OR a_airport.airport_name = 'Beirut International
Airport';

SELECT airplane_code, number_of_seats,


production_year, airplane_company
FROM Airplanes
WHERE production_year > 2010;

SELECT j.flight_number, j.journey_date,


d_airport.airport_name AS departing_airport,
a_airport.airport_name AS arrival_airport,
j.actual_departure_time, j.actual_arrival_time
FROM Journeys j
JOIN Airports d_airport ON j.departing_airport_code =
d_airport.airport_code
JOIN Airports a_airport ON j.arrival_airport_code =
a_airport.airport_code
WHERE j.journey_date = '2015-09-25';

Output
Query 1

Query 2

Query 3

Query 4
Query 5

Query 6

Query 7

Query 8

You might also like