我不知道爲什麼,這是行不通的:Postgres的聚集問題
SELECT u.id, u.tag, u.unit_type, Count(p.id) AS num_points
FROM ot2.unit u
INNER JOIN ot2.point p on p.unit_id = u.id
GROUP BY u.id
HAVING Count(p.id) > 800;
ERROR: column "u.tag" must appear in the GROUP BY clause or be used in an aggregate function SQL state: 42803
我已經被提供了一個列組。
這不會在所有RDBMS [除MySQL的]工作(http://mysql.lamphost.net/tech-resources/articles/debunking-group-by-myths的.html)。錯誤消息告訴你所有你需要知道的!它不要求「一列」。它會告訴你需要的確切額外的一個。你還需要理清'u.unit_type' –