在同一张桌子上执行合并

我想在同一张桌子上执行合并以合并两个不同的结果,来自两个不同区域的top3航班 但我无法执行order by子句才能获得两个选择的前3条记录,请帮助 可以使用SQL中的WITH子句完成相同的查询,但在MySQL上不起作用

sample dataSQL this is the desired result SQL

评论
切克闹
切克闹

You have two identical queries connected by union. Because union removes duplicates, this is equivalent to:

select count(*) as numberofflights, origin
from flights
where destination = 'EWR'
group by origin
order by numberofflights desc;

No union is necessary. Your version just adds much unneeded overhead.

点赞
评论