SQL Assingnment 2 (1)
SQL Assingnment 2 (1)
Invalid Submissions:
Pasting pictures of the code as answer is NOT acceptable
Uploading output data (CSVs) of the SQL queries is NOT acceptable
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';
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');
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;
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');
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
18. Identify date wise first cancelled flight id flying for every
airport?
Expected Output :
Flight_id,flight_number,schedule_departure,departure_airport
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%';