多重过滤(where ...)条件 PostgreSQL
Multiple filter (where ...) conditions PostgreSQL
我正在尝试 运行 使用多个过滤器进行以下查询。我不断收到错误消息。如果我单独 运行 过滤器,查询 运行 没问题。多个过滤器(其中...)是否不起作用?
select count(distinct a.user) as total
,count(distinct a.user) filter (where d.date >= current_date - '1 day'::interval) as 1_day
,count(distinct a.user) filter (where d.date >= current_date - '3 days'::interval) as 3_day
,count(distinct a.user) filter (where d.date >= current_date - '1 week'::interval) as 1_week
,count(distinct a.user) filter (where d.date >= current_date - '1 month'::interval) as 1_month
from ppl d
join
(select distinct t.user from tbl t
join date dd
on t.date::date between dd.month_start and dd.month_end
where dd.date = current_date - '14 days'::INTERVAL
) as a
on d.user = a.user
我收到此错误:
[Err] ERROR: syntax error at or near "1"
LINE 2: ....lastedit_date >= current_date - '1 day'::interval) as 1_day
^
来自docs:
SQL identifiers and key words must begin with a letter (a-z
, but also letters with diacritical marks and non-Latin letters) or an underscore (_
)
这意味着 1_day
不是有效的标识符,您不能将其用作不带双引号的列名。
我正在尝试 运行 使用多个过滤器进行以下查询。我不断收到错误消息。如果我单独 运行 过滤器,查询 运行 没问题。多个过滤器(其中...)是否不起作用?
select count(distinct a.user) as total
,count(distinct a.user) filter (where d.date >= current_date - '1 day'::interval) as 1_day
,count(distinct a.user) filter (where d.date >= current_date - '3 days'::interval) as 3_day
,count(distinct a.user) filter (where d.date >= current_date - '1 week'::interval) as 1_week
,count(distinct a.user) filter (where d.date >= current_date - '1 month'::interval) as 1_month
from ppl d
join
(select distinct t.user from tbl t
join date dd
on t.date::date between dd.month_start and dd.month_end
where dd.date = current_date - '14 days'::INTERVAL
) as a
on d.user = a.user
我收到此错误:
[Err] ERROR: syntax error at or near "1"
LINE 2: ....lastedit_date >= current_date - '1 day'::interval) as 1_day
^
来自docs:
SQL identifiers and key words must begin with a letter (
a-z
, but also letters with diacritical marks and non-Latin letters) or an underscore (_
)
这意味着 1_day
不是有效的标识符,您不能将其用作不带双引号的列名。