我正在从 MySQL 迁移到 Postgres。在 MySQL 中我可以使用
select sum(clicks) c from table where event_date >= '1999-01-01'
group by keyword_id
having c > 10
Postgres 报错
ERROR: column "c" does not exist
在 Postgres 中我必须重复 having 子句中的函数
select sum(clicks) c from table where event_date >= '1999-01-01'
group by keyword_id
having sum(clicks) > 10
代码中有很多地方我必须更改。 Postgres 中是否有允许它在 having 子句中使用列别名的设置?
最佳答案
Is there a setting in Postgres that will allow it to use column aliases in the having clause?
没有。允许在 HAVING
中引用 SELECT
列表条目的实现超出了标准。
您应该使用子查询,例如
select
c
from (
select
sum(clicks) c
from table
where event_date >= '1999-01-01'
group by keyword_id
) x
where c > 10;
...或重复聚合。
关于mysql - 在 Postgres 的 having 子句中引用一个选择聚合列别名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32730296/