分时间段统计交易数据

select a.shop_id,a.source_name,a.shop_jde_number,a.shop_open_date,
       case when crt_date >= shop_open_date and crt_date<=3_days then '3_days'
            when crt_date > 3_days and crt_date<=one_week then '3_to_one'
            when crt_date > one_week and crt_date<=two_week then 'two_week'
            when crt_date > two_week and crt_date<=three_week then 'three_week'
            when crt_date > two_week and crt_date<=three_week then 'three_week'
            when crt_date > three_week and crt_date<=30_days then 'three_to_30'
            when crt_date > 30_days and crt_date<=60_days then '30_to_60'
            when crt_date > 60_days and crt_date<=90_days then '60_to_90'
            when crt_date > 90_days and crt_date<=120_days then '90_to_120'
            end as period
            ,deliver_type
            ,sum(trade_amount),sum(order_quantity)
from (
select shop_id,source_name,shop_jde_number,shop_open_date,
ADDDATE(shop_open_date,INTERVAL 3 day) as 3_days,
ADDDATE(shop_open_date,INTERVAL 1 week) as one_week,
ADDDATE(shop_open_date,INTERVAL 2 week) as two_week,
ADDDATE(shop_open_date,INTERVAL 3 week) as three_week,
ADDDATE(shop_open_date,INTERVAL 30 day) as 30_days,
ADDDATE(shop_open_date,INTERVAL 60 day) as 60_days,
ADDDATE(shop_open_date,INTERVAL 90 day) as 90_days,
ADDDATE(shop_open_date,INTERVAL 120 day) as 120_days
from bigdata.dwd_shop_info_daily dsid 
where report_date >='2021-01-01'
and shop_open_date >='2021-01-01'
and shop_id  in (715,927,968)
group by 1,2,3
) a 
left join 
(
select  crt_date,shop_id,source_name,deliver_type,
sum(trade_amount) as trade_amount,sum(order_quantity) as order_quantity
from bigdata.dwd_trades_info_finaly_view  dssd 
where crt_date>='2021-01-01'
group by 1,2,3,4
)b 
on a.shop_id=b.shop_id  and a.source_name=b.source_name
and b.crt_date>=a.shop_open_date 
and b.crt_date<=a.120_days 
group by 1,2,3,4,5,6

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值