在PostgreSQL中运行以下查询时: -
SELECT group_,
COUNT(*),
MIN(time)
FROM TRIP
WHERE time >= NOW()
GROUP BY group_
ORDER BY time ASC
我收到错误: -
ERROR: column "trip.time" must appear in the GROUP BY clause or be used in an aggregate function
我不明白。 Isn&#t; t min
是一个聚合函数吗?此查询在MySql上运行。
答案 0 :(得分:0)
time
不是group by
项或聚合术语,因此您不能在具有group by
子句的查询中使用它。据推测,您打算按min(time)
订购,可以明确说明:
SELECT group_,
COUNT(*),
MIN(time)
FROM TRIP
WHERE time >= NOW()
GROUP BY group_
ORDER BY MIN(time) ASC
或者通过位置索引:
SELECT group_,
COUNT(*),
MIN(time)
FROM TRIP
WHERE time >= NOW()
GROUP BY group_
ORDER BY 3 ASC