【发布时间】:2020-03-04 07:56:44
【问题描述】:
我正在处理一个请求,以计算以下日期桶的表中唯一注册成员的数量(基于registration_date_utc - 时间戳),
1 月 1 日至 3 月 31 日:唯一注册会员数
2 月 1 日至 4 月 30 日:唯一注册会员数
3 月 1 日至 5 月 31 日:唯一注册会员计数
4 月 1 日至 6 月 30 日:唯一注册会员数
5 月 1 日至 7 月 31 日:唯一注册会员计数
6 月 1 日至 8 月 31 日:唯一注册会员数
7 月 1 日至 9 月 30 日:唯一注册会员数
8 月 1 日至 10 月 31 日:唯一注册成员计数
9 月 1 日至 11 月 30 日:唯一注册成员计数
10 月 1 日至 12 月 31 日:唯一注册成员计数
下面是我的 Snowflake 查询,它有效,但没有返回任何结果,
select
DATE_TRUNC('month',t.registration_date_utc) as "MONTH_START",
count(distinct t.MEMBER_ID)
FROM
(
select
member_id,
registration_date_utc
from table a
) as t
WHERE TO_DATE(t.registration_date_utc) BETWEEN DATEADD(month,'3',t.registration_date_utc) AND t.registration_date_utc
group by 1
order by 1;
【问题讨论】:
标签: sql date timestamp snowflake-cloud-data-platform