2016-04-12 16 views
0

複数のフィルタを使用して次のクエリを実行しようとしています。私は間違いを続ける。フィルタを個別に実行すると、クエリは正常に実行されます。複数のフィルター(どこか...)はうまくいきませんか?私はこのエラーを取得しています複数のフィルタ(where ...)条件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 
                   ^
+0

引用符で囲まれていない限り、フィールドエイリアス(1_day、3_day、...)は数字で始めることはできません(私は重複してチェックするのは怠けですが)。 –

答えて

2

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を意味有効な識別子ではありません、あなたは、二重なしで列名として使用することはできません引用符。