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
分时间段统计交易数据
最新推荐文章于 2022-10-08 11:30:15 发布