Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- select *
- from
- ( select p.requestid, p.reqnum, sum(p.f_productprice) ss , 1 type_
- from dwh_procedures_kgntv p
- join (select distinct lotuuid from dwh_lot_fin_kgntv where finyear = 2017)f on f.lotuuid = p.lotuuid
- where p.reqnum is not null and p.joflag = 0 and p.orgid = 2711
- group by p.requestid, p.reqnum
- )p
- where p.ss>=3000000 and p.ss<40000000
- union all
- select *
- from
- ( select p.requestid, p.reqnum, sum(p.f_productprice) ss, 2 type_
- from dwh_procedures_cons_kgntv p
- join (select distinct lotuuid from dwh_lot_fin_kgntv where finyear = 2017)f on f.lotuuid = p.lotuuid
- where p.reqnum is not null and p.orgid = 2711
- group by p.requestid, p.reqnum
- )p
- where p.ss>=3000000 and p.ss<40000000
- ;
- select p.requestid, p.reqnum,p.f_productprice,1 type_
- from dwh_procedures_kgntv p
- join (select distinct lotuuid from dwh_lot_fin_kgntv where finyear = 2017)f on f.lotuuid = p.lotuuid
- where p.reqnum is not null and uo_orgid = 2711 and p.joflag = 0
- union all
- select p.requestid, p.reqnum,p.f_productprice,2 type_
- from dwh_procedures_cons_kgntv p
- join (select distinct lotuuid from dwh_lot_fin_kgntv where finyear = 2017)f on f.lotuuid = p.lotuuid
- where p.reqnum is not null and uo_orgid = 2711
- ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement