2021-11-01
閱讀量:
7479
計算任意連續(xù)7天的累計客戶數(shù)
#### 計算任意連續(xù)7天的累計客戶數(shù),假設(shè)表里有3個字段, c_id 客戶ID,order_id,order_date 示例日期為17年7月1日到17年7月30日 #答案如下 select order_date 開始日期,date(order_date+ 6 ) 截止日期,concat(order_date,'~',date(order_date+6)) 時間段, sum(count(distinct c_id)) over( order by order_date rows between current row and 6 following) as 7天人數(shù) from order_info where order_date between '2017-07-01' and '2017-07-30' and date(order_date+6 ) is not null # 出現(xiàn)類似'2017-7-32'就是 null。 group by order_date ;






評論(3)

推薦帖子
0條評論
1條評論
0條評論