Salesperson(SSN, Name, StartYear, DeptNo)Answers:
Trip(SSN, FromCity, ToCity, DepartureDate, ReturnDate, TripId)
Expense(TripId, Account, Amount)
PROJECTSSN [ SELECTToCity = "Honolulu" (Trip) ]select SSN from Trip where ToCity = 'Honolulu';
PROJECTToCity ( [ SELECTName = "Bengt" (Salesperson) ] JOINSalesperson.SSN = Trip.SSN Salesperson )select ToCity from Salesperson, Trip where Name = 'Bengt' and Trip.SSN = Salesperson.SSN;
Fsum(Amount) ( [SELECTSSN = "234-56-7890"(Trip)] JOINTrip.TripId = Expense.TripId Expense )select sum(Amount) from Trip, Expense where SSN = '234-56-7890' and Trip.TripId = Expense.TripId;
ExpensiveTrips <- SELECTsum(Amount) > 2000 [ TripIDFsum(Amount) ( Expense ) ]select Trip.* from Trip, Expense where Trip.TripId = Expense.TripId group by Trip.TripId having sum(Amount) > 2000;
Salesperson.SSNFsum(Amount) [ ( Salesperson JOINSalesperson.SSN = Trip.SSN Trip ) JOINTrip.TripId = Expense.TripId Expense ]select Salesperson.SSN, sum(Amount) from Salesperson, Trip, Expense where Salesperson.SSN = Trip.SSN and Trip.TripId = Expense.TripId group by Salesperson.SSN;
Salesperson.SSNFsum(Amount) [ ( Salesperson LEFT OUTER JOINSalesperson.SSN = Trip.SSN Trip ) LEFT OUTER JOINTrip.TripId = Expense.TripId Expense ]select Salesperson.SSN, sum(Amount) from Salesperson left outer join Trip on Salesperson.SSN = Trip.SSN left outer join Expense on Trip.TripId = Expense.TripId group by Salesperson.SSN;
Or: Salesperson.SSNFsum(Amount) [ Salesperson LEFT OUTER JOINSalesperson.SSN = Trip.SSN ( Trip JOINTrip.TripId = Expense.TripId Expense ) ]
Note: The following doesn't work, since salespersons with no trips have no expenses either:
Salesperson.SSNFsum(Amount) [ ( Salesperson LEFT OUTER JOINSalesperson.SSN = Trip.SSN Trip ) JOINTrip.TripId = Expense.TripId Expense ]select Salesperson.SSN, sum(Amount) from Salesperson left outer join Trip on Salesperson.SSN = Trip.SSN, Expense where Trip.TripId = Expense.TripId group by Salesperson.SSN;
Salesperson JOINStartYear = min(StartYear) [ Fmin(StartYear) ( Salesperson ) ]select * from Salesperson where StartYear in (select min(StartYear) from Salesperson);