我正在尝试查找一个时间表中一个月内的活动订阅数。
表格:订阅字段:
在以下情况下,订阅被视为在特定时间戳下处于活动状态:
例:
这是我尝试的:
select "Month", sum(sub) over (order by "Month" asc) as "Active subscriptions"
from
(select to_char(subscriptions."creationDate" at time zone '-7', 'YYYY-MM') as "Month",
count(distinct subscriptions.id) as sub
from subscriptions
where (to_char(subscriptions."deletionDate" at time zone '-7', 'YYYY-MM') is null
or to_char(subscriptions."deletionDate" at time zone '-7', 'YYYY-MM') >= to_char(subscriptions."creationDate" at …Run Code Online (Sandbox Code Playgroud) 我每天都在努力寻找#活跃用户.
用户在连续 4 周每周发出超过 10个请求时处于活动状态.
即.2014年10月31日,如果用户每周总共发出超过10个请求,则用户处于活动状态:
我有一张桌子requests:
CREATE TABLE requests (
id text PRIMARY KEY, -- id of the request
amount bigint, -- sum of requests made by accounts_id to recipient_id,
-- aggregated on a daily basis based on "date"
accounts_id text, -- id of the user
recipient_id text, -- id of the recipient
date timestamp -- date that the request was made in YYYY-MM-DD
);
Run Code Online (Sandbox Code Playgroud)
样本值:
INSERT …Run Code Online (Sandbox Code Playgroud)