【发布时间】:2017-07-14 02:56:08
【问题描述】:
我正在尝试找出每个月的活跃用户(按年龄分组)。我尝试使用子查询,但出现错误。有没有体面的方法来做到这一点?谢谢!
with first_date_of_month as
(
SELECT current_date - (interval '1 month' * s.a) AS dates FROM
generate_series(0,24,1) AS s(a)
)
select q1.dates from first_date_of_month
where exists (select
case when round ((CURRENT_DATE - date_of_birth)/365) =<18 then '0-18'
...
when round ((CURRENT_DATE - date_of_birth)/365) >= 65 then '65+'
Else 'N/A' end as "Age",
count(1)
from users
and signup_date between q1.dates-INTERVAL '2 months' and q1.dates
group by 1 order by 1) ;
【问题讨论】:
-
您的查询毫无意义。尝试显示示例数据和所需结果。
标签: postgresql date time subquery series