MySQL Forums
Forum List  »  Optimizer & Parser

Re: Top 10 airports referenced from a table of flights
Posted by: Jani Patokallio
Date: June 16, 2009 03:35AM

Works! And another factor of ten or so faster, even after throwing in a join to get the airport names etc:

select a.name, a.iata, sum(x.ct) as count from
( select src_apid as apid, count(*) as ct
from flights
GROUP BY src_apid
UNION ALL
select dst_apid as apid, count(*) as ct
from flights
GROUP BY dst_apid
) x, airports as a
where a.apid=x.apid
group by x.apid
order by count desc
limit 10;

~4s with previous query, now down to 0.33s.

Options: ReplyQuote


Subject
Views
Written By
Posted
Re: Top 10 airports referenced from a table of flights
3286
June 16, 2009 03:35AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.