MySql:order by先于group by

MySql:order by先于group by,mysql,group-by,subquery,sql-order-by,grouping,Mysql,Group By,Subquery,Sql Order By,Grouping,我想在分组子查询之前对其进行排序。问题是,子查询是有序的,就好像我们把它当作一个查询一样。但作为子查询,orderby什么也不做 问题是: SELECT * FROM ( SELECT a.id, citypair, a.season, airline, class, fare, rbd, season_from, season_to, schedule_id, cp.departure_id, c

我想在分组子查询之前对其进行排序。问题是,子查询是有序的,就好像我们把它当作一个查询一样。但作为子查询,orderby什么也不做

问题是:

SELECT * FROM (
SELECT 
    a.id,
    citypair,
    a.season,
    airline,
    class,
    fare,
    rbd,
    season_from,
    season_to,
    schedule_id,
    cp.departure_id,
    cp.destination_id,
    sch.date_time
FROM tarifftool_price_log as a
JOIN tarifftool_seasons as b ON a.seasonId = b.id
JOIN tarifftool_citypairs as cp ON citypair = cp.id
JOIN tarifftool_schedule_queue AS sch ON schedule_id = sch.id
 WHERE       b.date = '12/26' AND class = 'b' ORDER BY schedule_id DESC) as qq 
GROUP BY citypair, airline 

现在,我只是尝试作为一个结果获得一个有序的查询。如果我做到了这一点,我将毫无问题地对数据进行分组。

在子查询中使用行号 行号()超过(按计划id排序)


在外部查询中放置ORDER BY子句有什么不对?添加到@Ctx:sub中的ORDER BY将一无所获。将orderby视为输出的最终格式,而子查询只是限制主查询要考虑的行数。祝你好运。因为我以后需要使用group by。我不能在下单后再分组,但你可以在分组后再下单。请显示,您希望如何分组
按城市航空公司分组,航空公司
表示您希望每个城市航空公司和航空公司有一个结果行。这与数据的顺序无关。那么你到底想达到什么目的呢?您知道,除了CityAir和airline之外,您选择的每一列都将从所有匹配项中任意选取,只要您不指定聚合函数(例如
SUM(fare)
MAX(seasure_from)
),是吗?
SELECT * FROM (
SELECT 
ROW_NUMBER() OVER(ORDER BY schedule_id DESC ) as RowId,
a.id,
citypair,
a.season,
airline,
class,
fare,
rbd,
season_from,
season_to,
schedule_id,
cp.departure_id,
cp.destination_id,
sch.date_time
FROM tarifftool_price_log as a
JOIN tarifftool_seasons as b ON a.seasonId = b.id
JOIN tarifftool_citypairs as cp ON citypair = cp.id
JOIN tarifftool_schedule_queue AS sch ON schedule_id = sch.id
WHERE       b.date = '12/26' AND class = 'b'  ) as qq 
GROUP BY citypair, airline