Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

DATABASE SYSTEM QUESTION /SQL QUERIES Consider the following relational schema f

ID: 3729163 • Letter: D

Question

DATABASE SYSTEM QUESTION /SQL QUERIES

Consider the following relational schema for the airport transfer database:

airport ( a-code, name, capacity)

customer ( c-id, name, birth-year, address)

vehicle ( plate, capacity, driver-name)

transfer( a-code, c-id, plate, year, ti-no)

ticket ( ti-no, price)

Give the corresponding SQL queries for each of the following. (a) Find the vehicle plates, which are used in the transfers to "Esenboa" Airport, and also have a driver whose name has at least five characters and starts with 'Z'. (b) List the airport codes with the total number of transfer tickets sold, and also total price. (c) Find the oldest customer's birth year and address, who have not bought any ticket yet. (d) Find the code and name of the airport with the 5th highest capacity. You can assume, for simplicity, that the capacity values are distinct. (e) Delete vehicles that have capacity lower than the average number of customers that are transferred by a vehicle in 2017.

NOTE: italic words represent primary keys.

Explanation / Answer

Note: Below SQL queries follow MySQL database syntax

Answer a:

select v.plate from vehicle v
inner join transfer t on v.plate=t.plate
inner join airport a on a.a-code=t.a-code
where a.name='Esenboa' and v.driver-name like 'Z_____%';

---------------------------------------------------------------------------------------------

Answer b:

select t.a-code,count(*) as total_transfer_ticket_sold, sum(tkt.price) as total_price from transfer t
inner join ticket tkt on t.ti-no=tkt.ti-no
group by t.a-code;

-------------------------------------------------------------------------------------

Answer c:

select c.name,c.birth-year,c.address from customer c
left join transfer t on c.c-id=t.c-id
where t.c-id is null
order by c.birth-year asc
limit 1;

-----------------------------------------------------------------------------------

Answer d:

select a.* from
(select * from airport order by capacity desc limit 5) a
order by a.capacity asc
limit 1;