Given the schema below write a query that returns the total flight time by tailn
ID: 3575611 • Letter: G
Question
Given the schema below write a query that returns the total flight time by tailnumber. In other words, one column should have the tailnumbers of aircraft, the other column should be the sum of the duration of that aircraft's flights. You may assume every aircraft has had at least one flight.
1 CREATE TABLE aircraft 2 tail number VARCHAR (20) PRIMARY KEY, 3 name VARCHAR (255) NOT NULL 6 CREATE TABLE flights 7 id INT PRIMARY KEY AUTO INCREMENT 8 departs VARCHAR (5) NOT NULL, 9 a rives VARCHAR (5) NOT NULL, 10 duration INT NOT NULL 11 aircraft. VARCHAR (20) NOT NULL, 12 FOREIGN REY (aircraft) REFERENCES aircraft (tailnumber 13Explanation / Answer
Hi,
Please see below the query. Please comment for any queries/feedbacks.
Thanks,
Anita
Query:
SELECT aircraft,SUM(duration)
FROM flights
GROUP BY aircraft;