1、***************************************************************************************
- select b.id,b.prod_name,sum(aa) as w1,sum(bb) as w2,sum(cc) as w3,sum(dd) as w4,sum(ee) as w5
- from (
- select a.id,a.prod_name,
- case a.iid when 1 then storeCount1 else 0 end as aa,
- case a.iid when 2 then storeCount1 else 0 end as bb,
- case a.iid when 3 then storeCount1 else 0 end as cc,
- case a.iid when 4 then storeCount1 else 0 end as dd,
- case a.iid when 5 then storeCount1 else 0 end as ee
- from (
- SELECT p.id,i.id as iid,p.prod_name,count(s.id) as storeCount1
- FROM BIZ_PROD_DISTRIBUTION d inner join
- BIZ_PROD_DISTRIBUTION_ITEM di on d.id=di.main_id inner join
- dim_store s on s.id=d.store_id inner join
- dim_dict_item i on i.id=s.store_type inner join
- dim_product p on p.id=di.prod_id
- where d.cate_type='1' and s.is_closed='1'
- group by p.prod_name,i.id,i.item_name,p.id) a
- ) b
- group by b.id,b.prod_name
2、***************************************************************************************
- select sum(g1.a1) as w1,sum(g1.a2) as w2,sum(g1.a3) as w3,sum(g1.a4) as w4,sum(g1.a5) as w5,
- sum(g1.b1) as s1,sum(g1.b2) as s2,sum(g1.b3) as s3,sum(g1.b4) as s4,sum(g1.b5) as s5
- from
- (select
- case h1.id when '1' then h1.storeTotal ELSE 0 end as a1,
- case h1.id when '2' then h1.storeTotal ELSE 0 end as a2,
- case h1.id when '3' then h1.storeTotal ELSE 0 end as a3,
- case h1.id when '4' then h1.storeTotal ELSE 0 end as a4,
- case h1.id when '5' then h1.storeTotal ELSE 0 end as a5,
- case h1.id when '1' then h1.callTotal ELSE 0 end as b1,
- case h1.id when '2' then h1.callTotal ELSE 0 end as b2,
- case h1.id when '3' then h1.callTotal ELSE 0 end as b3,
- case h1.id when '4' then h1.callTotal ELSE 0 end as b4,
- case h1.id when '5' then h1.callTotal ELSE 0 end as b5
- from
- (select i.id,x2.storeTotal,x3.callTotal
- from dim_dict_item i inner join
- (select s.store_type,count(s.id) as storeTotal
- from dim_store s
- where s.usage_flag='1' and s.is_closed='1'
- group by store_type)x2
- on i.id=x2.store_type
- inner join
- (select s.store_type,count(distinct c.STORE_ID) as callTotal
- from dim_store s
- inner join
- CALL_PLAN_ITEM c ON s.ID = c.STORE_ID
- where s.usage_flag='1' and s.is_closed='1'
- group by store_type)x3
- on x2.store_type=x3.store_type)h1)g1
3、*******************************************************************************************************************************
- select b.id,b.prod_name_en,sum(aa) as w1,sum(bb) as w2,sum(cc) as w3,sum(dd) as w4,sum(ee) as w5
- from (
- select a.id,a.prod_name_en,
- case a.iid when 1 then storeCount1 else 0 end as aa,
- case a.iid when 2 then storeCount1 else 0 end as bb,
- case a.iid when 3 then storeCount1 else 0 end as cc,
- case a.iid when 4 then storeCount1 else 0 end as dd,
- case a.iid when 5 then storeCount1 else 0 end as ee
- from (
- SELECT p.id,i.id as iid,p.prod_name_en,count(s.id) as storeCount1
- FROM BIZ_PROD_DISTRIBUTION d inner join
- BIZ_PROD_DISTRIBUTION_ITEM di on d.id=di.main_id inner join
- dim_store s on s.id=d.store_id inner join
- dim_dict_item i on i.id=s.store_type inner join
- dim_product p on p.id=di.prod_id
- inner join dim_geography g ON s.geo_id = g.id
- inner join dim_geography g1 ON g.parent_geography_id = g1.id
- where d.cate_type='2' and s.is_closed='1' and d.usage_flag='1' and s.usage_flag='1'
- group by p.prod_name_en,i.id,i.item_name,p.id) a
- ) b
- group by b.id,b.prod_name_en
4、***********************************************************************************************************************
- select b.id,b.prod_name_en,sum(aa) as w1,sum(bb) as w2,sum(cc) as w3,sum(dd) as w4,sum(ee) as w5
- from (
- select a.id,a.prod_name_en,
- case a.iid when 1 then storeCount1 else 0 end as aa,
- case a.iid when 2 then storeCount1 else 0 end as bb,
- case a.iid when 3 then storeCount1 else 0 end as cc,
- case a.iid when 4 then storeCount1 else 0 end as dd,
- case a.iid when 5 then storeCount1 else 0 end as ee
- from (
- SELECT p.id,i.id as iid,p.prod_name_en,count(s.id) as storeCount1
- FROM BIZ_PROD_DISTRIBUTION d inner join
- BIZ_PROD_DISTRIBUTION_ITEM di on d.id=di.main_id inner join
- dim_store s on s.id=d.store_id inner join
- dim_dict_item i on i.id=s.store_type inner join
- dim_product p on p.id=di.prod_id
- inner join dim_geography g ON s.geo_id = g.id
- inner join dim_geography g1 ON g.parent_geography_id = g1.id
- where d.cate_type='2' and s.is_closed='1' and d.usage_flag='1' and s.usage_flag='1'
- and $P!{queryString}
- group by p.prod_name_en,i.id,i.item_name,p.id) a
- ) b
- group by b.id,b.prod_name_en
5、**********************************************************************************************************************
- select b.id,b.prod_name_en,sum(aa) as w1,sum(bb) as w2,sum(cc) as w3,sum(dd) as w4,sum(ee) as w5
- from (
- select a.id,a.prod_name_en,
- case a.iid when 1 then storeCount1 else 0 end as aa,
- case a.iid when 2 then storeCount1 else 0 end as bb,
- case a.iid when 3 then storeCount1 else 0 end as cc,
- case a.iid when 4 then storeCount1 else 0 end as dd,
- case a.iid when 5 then storeCount1 else 0 end as ee
- from (
- SELECT p.id,i.id as iid,p.prod_name_en,count(s.id) as storeCount1
- FROM BIZ_PROD_DISTRIBUTION d inner join
- BIZ_PROD_DISTRIBUTION_ITEM di on d.id=di.main_id inner join
- dim_store s on s.id=d.store_id inner join
- dim_dict_item i on i.id=s.store_type inner join
- dim_product p on p.id=di.prod_id
- inner join dim_geography g ON s.geo_id = g.id
- inner join dim_geography g1 ON g.parent_geography_id = g1.id
- where d.cate_type='2' and s.is_closed='1' and d.usage_flag='1' and s.usage_flag='1'
- and $P!{queryString}
- group by p.prod_name_en,i.id,i.item_name,p.id) a
- ) b
- group by b.id,b.prod_name_en
6、****************************************************************************************************************
- select b.id,b.prod_name_en,sum(aa) as w1,sum(bb) as w2,sum(cc) as w3,sum(dd) as w4,sum(ee) as w5
- from (
- select a.id,a.prod_name_en,
- case a.iid when 1 then storeCount1 else 0 end as aa,
- case a.iid when 2 then storeCount1 else 0 end as bb,
- case a.iid when 3 then storeCount1 else 0 end as cc,
- case a.iid when 4 then storeCount1 else 0 end as dd,
- case a.iid when 5 then storeCount1 else 0 end as ee
- from (
- SELECT p.id,i.id as iid,p.prod_name_en,count(s.id) as storeCount1
- FROM BIZ_PROD_DISTRIBUTION d inner join
- BIZ_PROD_DISTRIBUTION_ITEM di on d.id=di.main_id inner join
- dim_store s on s.id=d.store_id inner join
- dim_dict_item i on i.id=s.store_type inner join
- dim_product p on p.id=di.prod_id
- inner join dim_geography g ON s.geo_id = g.id
- inner join dim_geography g1 ON g.parent_geography_id = g1.id
- where d.cate_type='1' and s.is_closed='1' and d.usage_flag='1' and s.usage_flag='1'
- and $P!{queryString}
- group by p.prod_name_en,i.id,i.item_name,p.id) a
- ) b
- group by b.id,b.prod_name_en