0% found this document useful (0 votes)
12 views

SQL Assingnment 2 (1)

The document provides a series of SQL query questions related to the Airline DB database, along with expected outputs and example answers. It outlines how to attempt the questions, submit the assignment, and specifies what constitutes invalid submissions. Each question requires a specific SQL query to retrieve data from the database, focusing on various aspects such as airport codes, flight counts, and aircraft details.

Uploaded by

satdarraman
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

SQL Assingnment 2 (1)

The document provides a series of SQL query questions related to the Airline DB database, along with expected outputs and example answers. It outlines how to attempt the questions, submit the assignment, and specifies what constitutes invalid submissions. Each question requires a specific SQL query to retrieve data from the database, focusing on various aspects such as airport codes, flight counts, and aircraft details.

Uploaded by

satdarraman
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Please answer the following questions using Airline DB database.

How to attempt questions:


 Students need to write queries for the questions mentioned in the
using Airline DB database
 Read the questions carefully before writing the query in Airline
Playground (in the Playground chapter of SQL)
 Airline DB: https://www.skillovilla.com/playground/sql?
exerciseId=0181e251-6ea8-4595-ae2b-0c690119f8db

How to submit the Assignment:


 Copy the SQL query code and paste it in the answer section in this
file
 Once the assignment is done, submit the file over LMS

Invalid Submissions:
 Pasting pictures of the code as answer is NOT acceptable
 Uploading output data (CSVs) of the SQL queries is NOT acceptable

Write your answers(query) in the answer and submit it. To write


the answer in the assignment, please follow the below example in
yellow
Example
Questions: Extract all the columns of the flights table
Answer: SELECT * FROM flights

1. Questions: Find list of airport codes in Europe/Moscow timezone


Expected Output: Airport_code

Answer: SELECT
airport_code
FROM AIRPORTS
where timezone='Europe/Moscow';
2. Write a query to get the count of seats in various fare condition
for every aircraft code?
Expected Outputs: Aircraft_code, fare_conditions ,seat count

Answer: SELECT
aircraft_code,
fare_conditions,
COUNT(seat_no) AS seat_count
FROM seats
GROUP BY aircraft_code,fare_conditions;

3. How many aircrafts codes have at least one Business class seats?
Expected Output : Count of aircraft codes

Answer: SELECT
COUNT(DISTINCT aircraft_code)
FROM seats
WHERE fare_conditions ='Business';

4. Find out the name of the airport having maximum number


of departure flight
Expected Output : Airport_name

Answer: SELECT a.airport_name


FROM airports a
JOIN flights f
ON a.airport_code = f.departure_airport
GROUP BY a.airport_name
ORDER BY COUNT(*) DESC
LIMIT 1;

5. Find out the name of the airport having least number of


scheduled departure flights
Expected Output : Airport_name

Answer: SELECT a.airport_name


FROM airports a
JOIN flights f
ON a.airport_code = f.departure_airport
GROUP BY a.airport_name
ORDER BY COUNT(*) asc
LIMIT 1;

6. How many flights from ‘DME’ airport don’t have actual


departure?
Expected Output : Flight Count

Answer: SELECT count(*) AS Flight_Count


from flights
where departure_airport ='DME' and actual_departure is
null ;

7. Identify flight ids having range between 3000 to 6000


Expected Output : Flight_Number , aircraft_code, ranges

Answer: SELECT
f.flight_no as Flight_Number,
a.aircraft_code,
a.range
from flights f
join aircrafts a
on f.aircraft_code = a.aircraft_code
where range between 3000 and 6000;

8. Write a query to get the count of flights flying between URS and
KUF?
Expected Output : Flight_count

Answer: SELECT
COUNT(*) AS Flight_Count
FROM flights
WHERE departure_airport='URS' AND
arrival_airport='KUF'
OR departure_airport='KUF' AND arrival_airport='URS' ;

9. Write a query to get the count of flights flying from either from
NOZ or KRR?
Expected Output : Flight count

Answer: SELECT
COUNT(*) AS Flight_Count
FROM flights
WHERE departure_airport in ('NOZ','KRR');

10. Write a query to get the count of flights flying from


KZN,DME,NBC,NJC,GDX,SGC,VKO,ROV
Expected Output : Departure airport ,count of flights flying from
these airports.

Answer: SELECT
departure_airport,
COUNT(*) AS Flight_Count
FROM flights
WHERE departure_airport in
('KZN','DME','NBC','NJC','GDX','SGC','VKO','ROV')
group by departure_airport;

11. Write a query to extract flight details having range between


3000 and 6000 and flying from DME
Expected Output :Flight_no,aircraft_code,range,departure_airport
Answer: SELECT
f.flight_no,
f.aircraft_code,
a.range,
f.departure_airport
FROM flights f
JOIN aircrafts a
ON f.aircraft_code = a.aircraft_code
WHERE a.range BETWEEN 3000 AND 6000
AND f.departure_airport = 'DME';

12. Find the list of flight ids which are using aircrafts from
“Airbus” company and got cancelled or delayed
Expected Output : Flight_id,aircraft_model

Answer: SELECT
f.flight_id,
a.model
FROM flights f
JOIN aircrafts a
ON f.aircraft_code = a.aircraft_code
WHERE a.model like '%Airbus%'
AND (f.status = 'Cancelled' OR f.status= 'Delayed');

13. Find the list of flight ids which are using aircrafts from
“Boeing” company and got cancelled or delayed
Expected Output : Flight_id,aircraft_model

Answer: SELECT
f.flight_id,
a.model
FROM flights f
JOIN aircrafts a
ON f.aircraft_code = a.aircraft_code
WHERE a.model like '%Boeing%'
AND (f.status = 'Cancelled'OR f.status='Delayed');

14. Which airport(name) has most cancelled flights (arriving)?


Expected Output : Airport_name

Answer: SELECT a.airport_name


FROM airports a
JOIN flights f ON a.airport_code = f.arrival_airport
WHERE f.status = 'Cancelled'
GROUP BY a.airport_name
ORDER BY COUNT(*) DESC
LIMIT 1;

15. Identify flight ids which are using “Airbus aircrafts”


Expected Output : Flight_id,aircraft_model

Answer: SELECT f.flight_id,


a.model AS Aircraft_model
FROM aircrafts a
JOIN flights f
ON a.aircraft_code = f.aircraft_code
WHERE a.model like '%Airbus%';

16. Identify date-wise last flight id flying from every airport?


Expected Output:
Flight_id,flight_number,schedule_departure,departure_airport

Answer: SELECT flight_id,


flight_no,
scheduled_departure,
departure_airport
FROM flights
group by departure_airport,flight_id,flight_no,
scheduled_departure
order by scheduled_departure desc;

17. Identify list of customers who will get the refund due to
cancellation of the flights and how much amount they will get?
Expected Output : Passenger_name,total_refund

Answer: SELECT t.passenger_name,


sum(tf.amount) AS total_refund
FROM ticket_flights tf
join flights f
ON tf.flight_id=f.flight_id
join tickets t
ON tf.ticket_no=t.ticket_no
WHERE f.status='Cancelled'
group by t.passenger_name
order by t.passenger_name asc;

18. Identify date wise first cancelled flight id flying for every
airport?
Expected Output :
Flight_id,flight_number,schedule_departure,departure_airport

Answer: ELECT flight_id,


flight_no,
scheduled_departure,
departure_airport,
status
FROM flights
where status ='Cancelled'
group by
departure_airport,flight_id,flight_no,scheduled_departure
order by scheduled_departure asc;

19. Identify list of Airbus flight ids which got cancelled.


Expected Output : Flight_id

Answer: select
flight_id
from flights f
join aircrafts a
ON f.aircraft_code=a.aircraft_code
where f.status ='Cancelled' and a.model like '%Airbus%';

20.Identify list of flight ids having highest range.


Expected Output : Flight_no, range

Answer: SELECT f.flight_no, a.range


FROM flights f
JOIN aircrafts a ON f.aircraft_code = a.aircraft_code
WHERE a.range = (SELECT MAX(range) FROM aircrafts);

You might also like