过滤器(其中......),可用于Postgres,但不能用于Redshift。

问题描述 投票:0回答:1

对于Redshift来说,在Postgres中可以实现的过滤器(where...)的替代方案是什么?我得到了以下错误,我无法弄清楚这在Redshift中是否不可能,或者我有一个语法错误:数据库报告了一个语法错误。Amazon Invalid operation: syntax error at or near "(" Position: 1521;

select count(distinct "agent.id")  as "agent_cnt"
, count(distinct "agent.id") filter (where "agent.status" = 'active' and ("agent.date" between '2020-01-01' and current_date)) as "active_agent_cnt"
from "agent" 
sql postgresql filter amazon-redshift where-clause
1个回答
1
投票

使用一个 case 表达式。

count(distinct case when "agent.status" = 'active' and ("agent.date" between '2020-01-01' and current_date then "agent.id" end) as "active_agent_cnt"

在列名中加入句号似乎非常可疑。 我坚决不鼓励这种命名习惯。

© www.soinside.com 2019 - 2024. All rights reserved.