我的 PostgreSQL 语句有什么问题?这在 MySql 上运行

What is wrong with my PostgreSQL statement? This runs on MySql

当 运行 在 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

我不明白。 min 不是聚合函数吗?此查询在 MySql.

上运行

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