我有以下查询在另一个DBMS中工作,但我无法在Redshift中使用它。它似乎不喜欢具有间隔的范围。关于如何相应修改它的任何建议?
COUNT(1) OVER (partition by include_flag,grouping_dimension,requested_hour,dow ORDER BY ts RANGE BETWEEN interval '30 days' PRECEDING AND interval '1 second' PRECEDING) as observations_grouping
谢谢!
答案 0 :(得分:1)
不幸的是,在Redshift中你可以指定要回头看的行数而不是精确的条件,对于你可以使用的条件加入
select include_flag,grouping_dimension,requested_hour,dow,count(1)
from source_table t1
join source_table t2
using (include_flag,grouping_dimension,requested_hour,dow)
where t2.ts between t1.ts-interval '30 day' and t1.ts-interval '1 second'
group by 1,2,3,4