对于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"
使用一个 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"
在列名中加入句号似乎非常可疑。 我坚决不鼓励这种命名习惯。