question

questionBoy9908 avatar image
questionBoy9908 asked

Find the Airline with the most number of flights

This is the flight and airline table
1624248330911.png

There are two airline with the most number of flights where is EA1709 and SA1865, can find the most number only, how do I find the Airline with the most number of flights.
Here is my query:

select max(y.total_flight) as most_number_of_flights

from (select Airline_ID, count(Flight_ID) as total_flight

from Flight

group by Airline_ID)y group by Airline_ID;

1624248357141.png

ThankYou!

countjoinmax
1624248330911.png (316.8 KiB)
1624248357141.png (112.4 KiB)
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

harbingergroup avatar image
harbingergroup answered
@questionBoy9908 
use below query to get your required output.

select top 1 AL.Airline_name,  count(AL.Airline_ID) from  Flight F
inner join Airline AL on F.Airline_ID = AL.Airline_ID
group by AL.Airline_name
order by count(AL.Airline_ID) desc
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

shahzaib5 avatar image
shahzaib5 answered
@questionBoy9908 This query can help you.

    SELECT
      MAX(Airline_ID) AS TotalFlights
    FROM (SELECT
        f.Flight_ID
       ,a.Airline_Name
       ,COUNT(Airline_ID) AS Total
      FROM FLIGHT AS F
      LEFT JOIN AIRLINE AS A
        ON A.Airline_ID = F.Airline_ID
      GROUP BY a.Airline_name) AS t; 
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.