帆软用户fsQZFgE6mk(提问者)
select
'' as sdt
--,'' as time_period
-- ,b.manage_dist_id,b.manage_dist_name
,b.manage_dist_id,b.manage_dist_name,b.prov_id_ud,b.prov_name_ud
-- ,b.manage_dist_id,b.manage_dist_name,b.prov_id_ud,b.prov_name_ud,b.city_id,b.city_name
-- ,b.manage_dist_id,b.manage_dist_name,b.prov_id_ud,b.prov_name_ud,b.region_id_ud,b.Region_Name_ud
-- ,b.manage_dist_id,b.manage_dist_name,b.prov_id_ud,b.prov_name_ud,b.region_id_ud,b.Region_Name_ud,b.shop_id,b.shop_name
,'' as goods_id1
,'' as goods_name1
,'汇总' as channel_dim_id
,'汇总' as channel_dim_desc
/*销售数量*/
,sum(case when (a.sdt BETWEEN '20240101' and '20240630') then sales_qty else 0 end) as sales_qty
,sum(case when (a.sdt BETWEEN '20230101' and '20230630') then sales_qty else 0 end) as sales_qty_y
/*销售额*/
,sum(case when (a.sdt BETWEEN '20240101' and '20240630') then restore_sales_amt else 0 end) as sales_amt
,sum(case when (a.sdt BETWEEN '20230101' and '20230630') then restore_sales_amt else 0 end) as sales_amt_y
/*毛利额*/
,sum(case when (a.sdt BETWEEN '20240101' and '20240630') then restore_gm_amt else 0 end) as gm_amt
,sum(case when (a.sdt BETWEEN '20230101' and '20230630') then restore_gm_amt else 0 end) as gm_amt_y
/*客流*/
,sum(case when (a.sdt BETWEEN '20240101' and '20240630') then custflow - ret_custflow else 0 end) as custflow
,sum(case when (a.sdt BETWEEN '20230101' and '20230630') then custflow - ret_custflow else 0 end) as custflow_y
from dws.dws_sale_tp_category_sales_1d a
inner join dim.dim_shop b on a.shop_id = b.shop_id and b.shop_sts='0000'
inner join (select sales_channel_id as channel_id
,sales_channel_name channel_desc
,is_online
,case when is_online='1' then '线上' else '线下' end as online_name
from dim.dim_channel
) as c on a.sales_channel_id=c.channel_id
where ((a.sdt BETWEEN '20240101' and '20240630')
or (a.sdt BETWEEN '20230101' and '20230630')
)
-- and time_period <>'99' -- 剔除时段99的汇总数据
and stat_flag = '1'
and a.shop_id in ('9200','9212','9238','9262','9301','9355','95G0', '95HG','95HS',
'9744','9745','9248','9414','9210','9259','9302','9321','9356','95A9','9605','9608'
,'9609','9249','9405','90B4','90T0','9211','9323','9415','9552','9584','9746'
,'9441','9652','9881')
-- and a.sales_channel_id in ('10','11','12','20','39','40','45','X1','Y5','Y6','Y7','Z1','30','31','32','33','34','36','37','38','41','42','43','44','46','48','49','50','51','52','53','54','55','56','57','58','59','60','61','62','63','64','66','67','68','69','70','71','72','73','74','75','76','77','78','79','80')
--and time_period BETWEEN '00' and '23'
and is_yoy='Y'
group by
sdt
,b.manage_dist_id,b.manage_dist_name,b.prov_id_ud,b.prov_name_ud
,channel_dim_id
,channel_dim_desc
,goods_id1
,goods_name1
order by
sdt
-- ,b.manage_dist_id,b.manage_dist_name
,b.manage_dist_id,b.manage_dist_name,b.prov_id_ud,b.prov_name_ud
,goods_id1
,channel_dim_id
,channel_dim_desc
limit 10000