Sei sulla pagina 1di 4

Nama : Abda Kurniawan Priyambada ( 18051214007 )

Maulana Auliyaurroshidin ( 18051214035 )


Achmad Andik ( 18051214039 )
8.17. Consider the AIRLINE relational database schema shown in Figure 5.8, which was
described in Exercise 5.12. Specify the following queries in relational algebra:

a) For each flight, list the flight number, the departure airport for the first leg of the
flight, and the arrival airport for the last leg of the flight.
b) List the flight numbers and weekdays of all flights or flight legs that depart
from Houston Intercontinental Airport (airport code ‘iah’) and arrive in Los Angeles
International Airport (airport code ‘lax’).
c) List the flight number, departure airport code, scheduled departure time, arrival
airport code, scheduled arrival time, and weekdays of all flights or flight legs that
depart from some airport in the city of Houston and arrive at some airport in the city
of Los Angeles.
d) List all fare information for flight number ‘co197’.
e) Retrieve the number of available seats for flight number ‘co197’ on ‘2009-10-09’.

a) Q1 ← Flight_number ℑ MIN Leg_number (FLIGHT_LEG)


Q2 ← Flight_number ℑ MAX Leg_number (FLIGHT_LEG)
Result ← π Flight_number,Departure_airport_code,Arrival_airport_code ((Q1×Q2) × AIRPORT)

b) Q1← σ Departure_airport_code=’IAH’ AND Arrival_airport_code=’LAX’ (FLIGHT_LEG)


Result ← π Flight_number, weekdays (FLIGHT × Q1)

c) Q1 ← σDeparture_airport_code = 'IAH'(FLIGHT_LEG)
Q2 ← σArrival_airport_code = 'LAX'(FLIGHT_LEG)
Q3 ← Q1 × Q2
Result ← πFlight_number, Departure_airport_code, Scheduled_departure_time, Arrival_airport_code, Scheduled_arrival_time,
Weekdays(Q3 × FLIGHT)
d) Result ← σ Flight_number = ‘CO197’ (FARE)

e) Q1 ← σ Flight_number = ‘CO197’ AND Date=’1990-10-09’ (LEG_INSTANCE)


Result ← π Number_of_available_seats (Q1)

8.23
Specify the following queries in relational algebra on the database schema in Exercise 5.17:
CAR(Serial_no, Model, Manufacturer, Price)
OPTION(Serial_no, Option_name, Price)
SALE(Salesperson_id, Serial_no, Date, Sale_price)
SALESPERSON(Salesperson_id, Name, Phone)
CAR

Serial_no Model Manufacturer Price

OPTION

Serial_no Option_name Price

SALE
Salesperson_id Serial_no Date Sale_price

SALESPERSON
Salesperson_id Name Phone

a) For the salesperson named ‘Jane Doe’, list the following information for all the cars
she sold: Serial#, Manufacturer, Sale_price.
b) List the Serial# and Model of cars that have no options.
c) Consider the NATURAL JOIN operation between SALESPERSON and SALE. What
is the meaning of a left outer join for these tables (do not change the order of
relations)? Explain with an example.
d) Write a query in relational algebra involving selection and one set operation and say
in words what the query does.

a) Q1 ← π Salesperson_id (σname = ‘jane doe’ SALESPERSON)


Q2 ← π Serial_no, Sale_price (Q1 ⋈ Salesperson_id = Salesperson_id SALE)
Result ← πSerial_no, Sale_price, Manufacturer (Q2 ⋈ Serial_no = Serial_no CAR)

b) Q1 ← π Serial_no, Model, Manufacturer, Price (CAR × OPTION)


Result ← π Serial-No, Model ( CAR – Q1 )

c) SALESPERSON ⟕ Salesperson_id = Salesperson_id SALES

SALESPERSON
Salesperson_id Name Phone
1 Abdul 085
2 Qodir 089
3 Jaelani 081

SALE
Salesperson_id Serial_no Date Sale_price
1 123 20301028 900
2 456 20301026 1000

Salesperson_id Name Phone Salesperson_id Serial_no Date Sale_price

1 Abdul 085 1 123 20301028 900


1 Abdul 085 2 456 20301026 1000
2 Qodir 089 1 123 20301028 900
2 Qodir 089 2 456 20301026 1000
3 Jaelani 081 1 123 20301028 900
3 Jaelani 081 2 456 20301026 1000

Result
Salesperson_id Name Phone Serial_no Date Sale_price
1 Abdul 085 123 20301028 900
2 Qodir 089 456 20301026 1000
3 Jaelani 081 NULL NULL NULL

Penjelasan : menampilkan semua data SALESPERSON dengan data penjualan


(SALE) mereka ( meskipun tidak memiliki data penjualan (SALE) )

d) Result ← SALESPERSON - σ Name = ‘Jane Doe’ (SALESPERSON)


query diatas menampilkan Salesperson_id, Name, Phone dari semua salesperson
kecuali ‘Jane Doe’

Potrebbero piacerti anche