此查询中的聚合函数内部未对时间进行排序:
SELECT id,
aggregate(time)
FROM (SELECT *
FROM TABLE
ORDER BY time) AS foo
GROUP BY something;
如何按表达式按列排序?
答案 0 :(得分:1)
您不应该在子查询上有ORDER BY
,而且您不需要它。
您可以在聚合函数的结果中添加ORDER BY
,但这不会影响聚合函数计算结果的方式。
如果您想影响聚合函数查看其参数的顺序,那么您可以向聚合函数添加ORDER BY
,但仅在某些数据库和某些情况下。
SELECT id, aggregate(time ORDER BY time)
FROM (SELECT * FROM TABLE) AS foo
GROUP BY something;
<强>实施例强>
答案 1 :(得分:0)
您无法在派生表内进行排序,您可以做的是
SELECT id,
aggregate(time)
FROM (SELECT *
FROM TABLE
) AS foo
GROUP BY something;
ORDER BY aggregate(time)