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

Write a SQL query on a relational flights database specified as follows. 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 
); 

Your Task: For each origin city, find the percentage of departing flights shorter than 3 hours. For this question, treat flights with null actual_time values as longer than 3 hours. Return the name of the city and the percentage value. Order by percentage value. Be careful to handle cities without any flights shorter than 3 hours. We will accept both 0 and NULL as the result for those cities.

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!