在此查询中,时间未在聚合函数内排序:
SELECT id,
aggregate(time)
FROM (SELECT *
FROM TABLE
ORDER BY time) AS foo
GROUP BY something;
如何按表达式分组内的列排序?
在此查询中,时间未在聚合函数内排序:
SELECT id,
aggregate(time)
FROM (SELECT *
FROM TABLE
ORDER BY time) AS foo
GROUP BY something;
如何按表达式分组内的列排序?
你不应该有ORDER BY
一个子查询,你也不需要它。
您可以ORDER BY
在聚合函数的结果中添加一个,但这不会影响聚合函数计算其结果的方式。
如果您想影响聚合函数查看其参数的顺序,那么您可以将 an 添加ORDER BY
到聚合函数,但仅限于某些数据库和某些情况下。
SELECT id, aggregate(time ORDER BY time)
FROM (SELECT * FROM TABLE) AS foo
GROUP BY something;
例子
您不能在派生表中排序,您可以做的是
SELECT id,
aggregate(time)
FROM (SELECT *
FROM TABLE
) AS foo
GROUP BY something;
ORDER BY aggregate(time)