我试图通过时间序列获得Redshift中不同对象的累积计数.直截了当的是使用COUNT(DISTINCT myfield)OVER(ORDER BY timefield DESC ROWS UNBOUNDED PRECEDING),但Redshift给出了"不支持窗口定义"错误.
例如,下面的代码试图找到从第一周到现在的每周累积的不同用户.但是,我得到"不支持窗口功能"错误.
SELECT user_time.weeks_ago,
COUNT(distinct user_time.user_id) OVER
(ORDER BY weeks_ago desc ROWS UNBOUNDED PRECEDING) as count
FROM (SELECT FLOOR(EXTRACT(DAY FROM sysdate - ev.time) / 7) AS weeks_ago,
ev.user_id as user_id
FROM events as ev
WHERE ev.action='some_user_action') as user_time
Run Code Online (Sandbox Code Playgroud)
目标是构建执行操作的唯一用户的累积时间序列.关于如何做到这一点的任何想法?
我的问题类似于redshift:在窗口分区上计算不同的客户,但我有一个滚动窗口分区。
我的查询看起来像这样,但不支持Redshift中的 COUNT 内的不同查询
select p_date, seconds_read,
count(distinct customer_id) over (order by p_date rows between unbounded preceding and current row) as total_cumulative_customer
from table_x
Run Code Online (Sandbox Code Playgroud)
我的目标是计算截至每个日期的唯一客户总数(因此是滚动窗口)。
我尝试使用dense_rank()方法,但它会失败,因为我不能使用这样的窗口函数
select p_date, max(total_cumulative_customer) over ()
(select p_date, seconds_read,
dense_rank() over (order by customer_id rows between unbounded preceding and current row) as total_cumulative_customer -- WILL FAIL HERE
from table_x
Run Code Online (Sandbox Code Playgroud)
任何解决方法或不同的方法都会有所帮助!
编辑:
输入数据样本
+------+----------+--------------+
| Cust | p_date | seconds_read |
+------+----------+--------------+
| 1 | 1-Jan-20 | 10 |
| 2 …
Run Code Online (Sandbox Code Playgroud)