Question: Write two SQL queries on a relational flights database specified below. The database contains one table called Flights , whose scheme is as follows: Flights

Write two SQL queries on a relational flights database specified below. The database contains one table called Flights, whose scheme is as follows:

Flights (fid, year, month_id, day_of_month, day_of_week_id, carrier_id, flight_num, origin_city, origin_state, dest_city, dest_state, departure_delay, taxi_out, arrival_delay, canceled, actual_time, distance)

Suppose that the following table has been created successfully (so you don't need to worry about creating the table but just focus on writing the queries. However, you probably need to pay attention to the data type defined for each attribute):

CREATE TABLE Flights ( 
 fid integer PRIMARY KEY, 
 year varchar(4), 
 month_id integer, 
 day_of_month integer, 
 day_of_week_id integer, 
 carrier_id varchar(10), 
 flight_num integer, 
 origin_city varchar(30), 
 origin_state varchar(20), 
 dest_city varchar(30), 
 dest_state varchar(20), 
 departure_delay integer, 
 taxi_out integer, 
 arrival_delay integer, 
 canceled integer, 
 actual_time integer, 
 distance integer 
); 

Query 1: For each origin city, find the destination city (or cities) with the longest direct flight. By direct flight, we mean a flight with no intermediate stops. Judge the longest flight in time, not distance. Show the name of the origin city, destination city, and the flight time between them. Do not include duplicates of the same origin/destination city pair. Order the result by origin_city name then destination city name.

Query 2: Find all origin cities that only serve flights shorter than 3 hours. You can assume that flights with NULL actual_time are not 3 hours or more. Return only the names of the cities sorted by name. List each city only once in the result.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!