1. SQL
Q1
Find all passengers, between the ages of 20 and 30 (inclusive), who have a “Vegan” or “Vegetarian” dietary preference. Return their ID, name, and age.
Q2
a. Find the number of airplanes that exist for each model. Return the model and the count for each model. b. Extend your query from (a) to find the number of airplanes in each model for any of the following airlines: ‘Air Canada’, ‘Etihad Airways’, or ‘United Airlines’. Return the name of the airline, the model, and the number of airplanes.
Q3
a. For each “Air Canada” ticket, find the average of the total weight, for all baggage associated to the ticket. Return the ticket number, and the average total (baggage) weight. b. Find all tickets with “Oversized”, non-fragile baggage with a total weight (strictly) greater than 90 lbs, during the holiday season from Dec. 10, 2023 to Jan. 3, 2024 (inclusive). Return all qualifying ticket numbers, and the total
(Oversized)
baggage weight.
Q4
Where and when are the cheapest tickets for flights from Toronto “YYZ” to Orlando “MCO”? Return the ticket number, the date of departure, the minimum price (rename to min-Price), and the website where the ticket(s) were purchased.
Q5
a. Which routes are served by at least three airlines? Return the routeID, and display your results in descending order by the number of airlines. b. Which routes are not served by any airline? Return the routeID, the source and destination airports
Q6
a. Find the number of distinct passengers who also work as either a pilot, cabin crew, or ground staff. Rename this result as NumStaffPassengers. b. For each airline, how many pilots or cabin crew are also passengers? Return the airline (alias), and the corresponding count
Q7
a. Find all the one-way routes operated by airline “ACA”, i.e., airline alias = ‘ACA’. In this context, a one-way route is where the airline serves from a source airport to a destination airport, but not in the reverse direction. Return the route ID, and the corresponding source and destination airports, respectively. b. Find the most popular route where the departure date lies between “2023-12-01” to “2023-12-31” (inclusive). Popularity is defined as the maximum number of tickets purchased during this time duration. Return the route ID, the corresponding source and destination air- ports, and number of tickets sold along this route.
Q8
a. Which Air Canada (alias “ACA”) flights from source airport “YYZ” to destination airport “MCO” have “First” class tickets? Return all satisfying flight numbers. b. Find all airlines that are unique to their country (i.e., they are the only airline for their country). Return the airline alias, airline name, and the country name
2. Relational Algebra
Question
For queries Q1 - Q6, give the corresponding relational algebra expression
Q1
Q2
a.
b.
Q3
a.
NOTE: R2 should “\leftouterjoin” instead (but current limitation of LaTeX renderer)
b.
Q4
Q5
a.
b.
NOTE: Route should “\leftouterjoin” instead (but current limitation of LaTeX renderer)
Q6
a.
b.
3. Indexes
The following includes two possible indexes:
on ScheduledFlight
table
- Attributes: (FlightNo, DeptDate) on
ScheduledFlight
table - Properties: composite index on both attributes , clustered index respectively
- Benefits
- Q3, Q4, Q7b given these queries heavily join with ScheduledFlight and filter on depature dates
- composite nature supports queries that use both FlightNo and DepDate in joins (frequently due to the foreign key relationship with Ticket table)
- Since these fields are part of the primary key of ScheduledFlight and are frequently used in joins with Ticket
- help with range scan on DepDate
on Use
table
- Attributes: (RouteID, AirlineAlias) on
Use
table - Properties: composite index., unclustered index respectively
- Benefits:
- Q5a, Q5b, Q7a and indirect Q4
- given these rely on route-airline relationship
- Q5a needs to count distinct airlines per route, so this index eliminate this scan
- Q7a looks for ACA airline routes, so this will provide direct access
- Being unclustered is appropriate as
Use
is frequently accessed for lookups but doesn’t require physical ordering