我需要的是每天显示最近5天(含)的新滴管的累积(移动)数量
分为美国与非美国地理位置。
报告列:
DataTimstamp-5天时间范围的上限
总计-在时间范围内的新滴管数量
Region_US-国家(地区)=“美国”的新投放站数量
Region_rest-国家<>“美国”
这是我的代码:
Create view new_droppers_per_date as Select date,country,count(dropperid) as num_new_customers
From(
Select dropper id,country,min(cast( LoginTimestamp as date)) as date
From droppers) as t1 group by date,country
Select DataTimstamp,region_us,region_rest from(
(Select date as DataTimstamp ,sum(num_new_customers) over(oreder by date range between 5
preceding and 1 preceding) as total
From new_droppers_per_date ) as t1 inner join
(Select date ,sum(num_new_customers) over(oreder by date range between 5 preceding and preceding)
as region_us
From new_droppers_per_date where country=”us”) as t2 on t1.date=t2.date inner join
(Select date, sum(num_new_customers) over(oreder by date range between 5 preceding and 1
preceding)
as region_rest
From new_droppers_per_date where country <>”us”) as t3 on t2.date=t3.date)
我想知道是否有任何更简便,更智能的方法而无需使用太多联接和视图
感谢您的帮助:)