- select * from ( select * from(
- select sum(isnull(aa,0)) as a,sum(bb)as b,sum(cc)as c,sum(dd)as d,sum(ee)as e
- from ( select
- case c1.store_type when 1 then a1StoreCount else 0 end as aa,
- case c1.store_type when 2 then a1StoreCount else 0 end as bb,
- case c1.store_type when 3 then a1StoreCount else 0 end as cc,
- case c1.store_type when 4 then a1StoreCount else 0 end as dd,
- case c1.store_type when 5 then a1StoreCount else 0 end as ee
- from ( SELECT a1.store_type,a1.item_name, count(a1.store_id) as a1StoreCount
- FROM BIZ_PROD_PRICE p inner join
- (SELECT s.store_type,p.id,p.store_id,i.id as iid,i.item_name, pd.prod_name, pi.prod_price
- FROM BIZ_PROD_PRICE p INNER JOIN
- BIZ_PROD_PRICE_ITEM pi ON p.id = pi.main_id INNER JOIN
- dim_store s on s.id=p.store_id inner join
- dim_dict_item i on i.id=s.store_type inner join
- dim_product pd ON pd.id = pi.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 pd.id = 284 and $P!{queryString}) a1 on p.id=a1.id INNER JOIN
- (SELECT p.id,p.store_id,i.id as iid,i.item_name, pd.prod_name, pi.prod_price
- FROM BIZ_PROD_PRICE p INNER JOIN
- BIZ_PROD_PRICE_ITEM pi ON p.id = pi.main_id INNER JOIN
- dim_store s on s.id=p.store_id inner join
- dim_dict_item i on i.id=s.store_type inner join
- dim_compt_prod pd ON pd.id = pi.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 pd.id = 17 and $P!{queryString}) a2 ON a1.store_id = a2.store_id AND
- a1.prod_price > a2.prod_price and a1.iid=a2.iid
- group by a1.item_name,a1.store_type
- )c1
- )e1)d,
- (select sum(aa) as a1,sum(bb)as b1,sum(cc)as c1,sum(dd)as d1,sum(ee)as e1
- from ( select
- case c1.store_type when 1 then a1StoreCount else 0 end as aa,
- case c1.store_type when 2 then a1StoreCount else 0 end as bb,
- case c1.store_type when 3 then a1StoreCount else 0 end as cc,
- case c1.store_type when 4 then a1StoreCount else 0 end as dd,
- case c1.store_type when 5 then a1StoreCount else 0 end as ee
- from (SELECT a1.store_type,a1.item_name, count(a1.store_id) as a1StoreCount FROM
- BIZ_PROD_PRICE p inner join
- (SELECT s.store_type,p.id,p.store_id,i.id as iid,i.item_name, pd.prod_name, pi.prod_price
- FROM BIZ_PROD_PRICE p INNER JOIN
- BIZ_PROD_PRICE_ITEM pi ON p.id = pi.main_id INNER JOIN
- dim_store s on s.id=p.store_id inner join
- dim_dict_item i on i.id=s.store_type inner join
- dim_product pd ON pd.id = pi.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 pd.id = 284 and $P!{queryString}) a1 on p.id=a1.id INNER JOIN
- (SELECT p.id,p.store_id,i.id as iid,i.item_name, pd.prod_name, pi.prod_price
- FROM BIZ_PROD_PRICE p INNER JOIN
- BIZ_PROD_PRICE_ITEM pi ON p.id = pi.main_id INNER JOIN
- dim_store s on s.id=p.store_id inner join
- dim_dict_item i on i.id=s.store_type inner join
- dim_compt_prod pd ON pd.id = pi.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 pd.id = 50 and $P!{queryString}) a2 ON a1.store_id = a2.store_id AND
- a1.prod_price > a2.prod_price and a1.iid=a2.iid and p.id=a2.id
- group by a1.item_name,a1.store_type
- )c1
- )e2)d1,
- (
- select sum(aa) as a2,sum(bb)as b2,sum(cc)as c2,sum(dd)as d2,sum(ee)as e2
- from ( select
- case c1.store_type when 1 then a1StoreCount else 0 end as aa,
- case c1.store_type when 2 then a1StoreCount else 0 end as bb,
- case c1.store_type when 3 then a1StoreCount else 0 end as cc,
- case c1.store_type when 4 then a1StoreCount else 0 end as dd,
- case c1.store_type when 5 then a1StoreCount else 0 end as ee
- from (SELECT a1.store_type,a1.item_name,count(a1.store_id) as a1StoreCount FROM
- BIZ_PROD_PRICE p inner join
- (SELECT s.store_type,p.id,p.store_id,i.id as iid,i.item_name, pd.prod_name, pi.prod_price
- FROM BIZ_PROD_PRICE p INNER JOIN
- BIZ_PROD_PRICE_ITEM pi ON p.id = pi.main_id INNER JOIN
- dim_store s on s.id=p.store_id inner join
- dim_dict_item i on i.id=s.store_type inner join
- dim_product pd ON pd.id = pi.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 pd.id = 343 and $P!{queryString}) a1 on p.id=a1.id INNER JOIN
- (SELECT p.id,p.store_id,i.id as iid,i.item_name, pd.prod_name, pi.prod_price
- FROM BIZ_PROD_PRICE p INNER JOIN
- BIZ_PROD_PRICE_ITEM pi ON p.id = pi.main_id INNER JOIN
- dim_store s on s.id=p.store_id inner join
- dim_dict_item i on i.id=s.store_type inner join
- dim_compt_prod pd ON pd.id = pi.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 pd.id = 22 and $P!{queryString}) a2 ON a1.store_id = a2.store_id AND
- a1.prod_price > a2.prod_price and a1.iid=a2.iid
- group by a1.item_name,a1.store_type
- )c1
- )e3)d2,
- (
- select sum(aa) as a3,sum(bb)as b3,sum(cc)as c3,sum(dd)as d3,sum(ee)as e3
- from ( select
- case c1.store_type when 1 then a1StoreCount else 0 end as aa,
- case c1.store_type when 2 then a1StoreCount else 0 end as bb,
- case c1.store_type when 3 then a1StoreCount else 0 end as cc,
- case c1.store_type when 4 then a1StoreCount else 0 end as dd,
- case c1.store_type when 5 then a1StoreCount else 0 end as ee
- from (SELECT a1.store_type,a1.item_name,count(a1.store_id) as a1StoreCount FROM
- BIZ_PROD_PRICE p inner join
- (SELECT s.store_type,p.id,p.store_id,i.id as iid,i.item_name, pd.prod_name, pi.prod_price
- FROM BIZ_PROD_PRICE p INNER JOIN
- BIZ_PROD_PRICE_ITEM pi ON p.id = pi.main_id INNER JOIN
- dim_store s on s.id=p.store_id inner join
- dim_dict_item i on i.id=s.store_type inner join
- dim_product pd ON pd.id = pi.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 pd.id = 341 and $P!{queryString}) a1 on p.id=a1.id INNER JOIN
- (SELECT p.id,p.store_id,i.id as iid,i.item_name, pd.prod_name, pi.prod_price
- FROM BIZ_PROD_PRICE p INNER JOIN
- BIZ_PROD_PRICE_ITEM pi ON p.id = pi.main_id INNER JOIN
- dim_store s on s.id=p.store_id inner join
- dim_dict_item i on i.id=s.store_type inner join
- dim_compt_prod pd ON pd.id = pi.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 pd.id = 22 and $P!{queryString}) a2 ON a1.store_id = a2.store_id AND
- a1.prod_price > a2.prod_price and a1.iid=a2.iid
- group by a1.item_name,a1.store_type
- )c1
- )e4)d3,
- (
- select sum(aa) as a4,sum(bb)as b4,sum(cc)as c4,sum(dd)as d4,sum(ee)as e4
- from (
- select
- case c1.store_type when 1 then a1StoreCount else 0 end as aa,
- case c1.store_type when 2 then a1StoreCount else 0 end as bb,
- case c1.store_type when 3 then a1StoreCount else 0 end as cc,
- case c1.store_type when 4 then a1StoreCount else 0 end as dd,
- case c1.store_type when 5 then a1StoreCount else 0 end as ee
- from
- (SELECT a1.store_type,a1.item_name,count(a1.store_id) as a1StoreCount
- FROM
- BIZ_PROD_PRICE p inner join
- (SELECT s.store_type,p.id,p.store_id,i.id as iid,i.item_name, pd.prod_name, pi.prod_price
- FROM BIZ_PROD_PRICE p INNER JOIN
- BIZ_PROD_PRICE_ITEM pi ON p.id = pi.main_id INNER JOIN
- dim_store s on s.id=p.store_id inner join
- dim_dict_item i on i.id=s.store_type inner join
- dim_product pd ON pd.id = pi.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 pd.id = 345 and $P!{queryString}) a1 on p.id=a1.id INNER JOIN
- (SELECT p.id,p.store_id,i.id as iid,i.item_name, pd.prod_name, pi.prod_price
- FROM BIZ_PROD_PRICE p INNER JOIN
- BIZ_PROD_PRICE_ITEM pi ON p.id = pi.main_id INNER JOIN
- dim_store s on s.id=p.store_id inner join
- dim_dict_item i on i.id=s.store_type inner join
- dim_compt_prod pd ON pd.id = pi.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 pd.id = 22 and $P!{queryString}) a2 ON a1.store_id = a2.store_id AND
- a1.prod_price > a2.prod_price and a1.iid=a2.iid
- group by a1.item_name,a1.store_type
- )c1
- )e5)d4
- )w1,
- ---lower-----------------------------------------------------------------
- ( select * from(
- select sum(isnull(aa,0)) as sa,sum(bb)as sb,sum(cc)as sc,sum(dd)as sd,sum(ee)as se from (
- select
- case c1.store_type when 1 then a1StoreCount else 0 end as aa,
- case c1.store_type when 2 then a1StoreCount else 0 end as bb,
- case c1.store_type when 3 then a1StoreCount else 0 end as cc,
- case c1.store_type when 4 then a1StoreCount else 0 end as dd,
- case c1.store_type when 5 then a1StoreCount else 0 end as ee
- from ( SELECT a1.store_type,a1.item_name, count(a1.store_id) as a1StoreCount FROM
- BIZ_PROD_PRICE p inner join
- (SELECT s.store_type,p.id,p.store_id,i.id as iid,i.item_name, pd.prod_name, pi.prod_price
- FROM BIZ_PROD_PRICE p INNER JOIN
- BIZ_PROD_PRICE_ITEM pi ON p.id = pi.main_id INNER JOIN
- dim_store s on s.id=p.store_id inner join
- dim_dict_item i on i.id=s.store_type inner join
- dim_product pd ON pd.id = pi.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 pd.id = 284 and $P!{queryString}) a1 on p.id=a1.id INNER JOIN
- (SELECT p.id,p.store_id,i.id as iid,i.item_name, pd.prod_name, pi.prod_price
- FROM BIZ_PROD_PRICE p INNER JOIN
- BIZ_PROD_PRICE_ITEM pi ON p.id = pi.main_id INNER JOIN
- dim_store s on s.id=p.store_id inner join
- dim_dict_item i on i.id=s.store_type inner join
- dim_compt_prod pd ON pd.id = pi.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 pd.id = 17 and $P!{queryString}) a2 ON a1.store_id = a2.store_id AND
- a1.prod_price <= a2.prod_price and a1.iid=a2.iid
- group by a1.item_name,a1.store_type
- )c1 )e1)d,
- (select sum(aa) as sa1,sum(bb)as sb1,sum(cc)as sc1,sum(dd)as sd1,sum(ee)as se1
- from ( select
- case c1.store_type when 1 then a1StoreCount else 0 end as aa,
- case c1.store_type when 2 then a1StoreCount else 0 end as bb,
- case c1.store_type when 3 then a1StoreCount else 0 end as cc,
- case c1.store_type when 4 then a1StoreCount else 0 end as dd,
- case c1.store_type when 5 then a1StoreCount else 0 end as ee
- from
- (SELECT a1.store_type,a1.item_name, count(a1.store_id) as a1StoreCount
- FROM
- BIZ_PROD_PRICE p inner join
- (SELECT s.store_type,p.id,p.store_id,i.id as iid,i.item_name, pd.prod_name, pi.prod_price
- FROM BIZ_PROD_PRICE p INNER JOIN
- BIZ_PROD_PRICE_ITEM pi ON p.id = pi.main_id INNER JOIN
- dim_store s on s.id=p.store_id inner join
- dim_dict_item i on i.id=s.store_type inner join
- dim_product pd ON pd.id = pi.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 pd.id = 284 and $P!{queryString}) a1 on p.id=a1.id INNER JOIN
- (SELECT p.id,p.store_id,i.id as iid,i.item_name, pd.prod_name, pi.prod_price
- FROM BIZ_PROD_PRICE p INNER JOIN
- BIZ_PROD_PRICE_ITEM pi ON p.id = pi.main_id INNER JOIN
- dim_store s on s.id=p.store_id inner join
- dim_dict_item i on i.id=s.store_type inner join
- dim_compt_prod pd ON pd.id = pi.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 pd.id = 50 and $P!{queryString}) a2 ON a1.store_id = a2.store_id AND
- a1.prod_price <= a2.prod_price and a1.iid=a2.iid and p.id=a2.id
- group by a1.item
sql 整理(三)
sql 代碼
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.