Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- select w_o_eco.*, eco.eco from (select fgrbsname,
- sum(
- case when number_ in (5, 6, 11, 12) then price else 0 end) / 1000000 as yearly,
- sum(
- case when number_ in (5, 6, 11, 12) and uoplacing = 1 then price else 0 end) / 1000000 as yearlyuo,
- sum(
- case when number_ in (11, 12) then price else 0 end) / 1000000 as yearlyisp,
- sum(
- case when number_ in (11, 12) and uoplacing = 1 then price else 0 end) / 1000000 as yearlyispuo,
- sum(
- case when number_ in (5, 6, 11, 12) and extract( month from plannedplacementdate) = 4 then price else 0 end) / 1000000 as monthly,
- sum(
- case when number_ in (11, 12) and extract( month from plannedplacementdate) = 4 then price else 0 end) / 1000000 as monthlyisp,
- sum(
- case when number_ in (6) and extract( month from plannedplacementdate) = 4 then price else 0 end) / 1000000 as monthlypalce,
- sum(
- case when number_ in (5, 6, 11, 12) and extract( month from plannedplacementdate) = 5 then price else 0 end) / 1000000 as nextmonthly
- from sppr_plan_placement
- where fgrbsname not in ('Уполномоченный по защите прав предпринимателей в Санкт-Петербурге', 'Уполномоченный по правам ребенка в Санкт-Петербурге', 'Уполномоченный по правам человека в Санкт-Петербурге', 'Уставный суд Санкт-Петербурга', 'Контрольно-счётная палата Санкт-Петербурга', 'Санкт-Петербургская избирательная комиссия', 'Законодательное Собрание Санкт-Петербурга')
- group by fgrbsname) w_o_eco full outer join
- (select fgrbsname,
- sum(nmc) nmc,
- sum(sum_) concost,
- sum(eco) eco
- from (
- (select src.fgrbsname fgrbsname,
- flotnmc nmc,
- sum_,
- case when (flotnmc - sum_) > 0 then (flotnmc - sum_) else 0 end / 1000000 eco
- from
- (select ldm.uuid,
- ldm.offer,
- ldm.joflag,
- case when joflag = 0 then ldm.customer else tb.parentid end org,
- ldm.flotnmc,
- cs.sum_
- from sppr_lot_data_nmc ldm
- inner join
- (select sc.lot,
- sum(sc.contractcost)sum_
- from sppr_contract sc
- inner join site_contracts_req_2015 r15
- on r15.uuid = sc.contract
- inner join sppr_ref_order_type srot
- on srot.fordertypeuuid = sc.ordertype
- where srot.fcompetitionflag = 1
- group by sc.lot
- )cs on cs.lot = ldm.uuid
- inner join tbl_bo tb
- on tb.uuid = ldm.offer
- inner join
- (select distinct dor.offer uuid
- from sppr_plan_placement spp
- inner join dwh_offer_request_t dor
- on dor.request = spp.reqid
- where number_ in (5, 6, 11, 12)
- )offer on offer.uuid = ldm.offer
- )lot
- inner join sppr_ref_customer_tbl src
- on src.orgid = lot.org
- where src.fgrbsname not in ('Уполномоченный по защите прав предпринимателей в Санкт-Петербурге', 'Уполномоченный по правам ребенка в Санкт-Петербурге', 'Уполномоченный по правам человека в Санкт-Петербурге', 'Уставный суд Санкт-Петербурга', 'Контрольно-счётная палата Санкт-Петербурга', 'Санкт-Петербургская избирательная комиссия', 'Законодательное Собрание Санкт-Петербурга')
- )
- union all
- (select src.fgrbsname,
- nvl(srf.nmc, 0) nmc,
- nvl(srf.concost, 0) concost,
- case when (srf.nmc - srf.concost) > 0 then (srf.nmc - srf.concost) else 0 end / 1000000 eco
- from
- (select distinct orginn from sppr_request_financing
- ) orgs
- left join
- (select distinct lot_id,
- nmc,
- concost,
- orginn,
- order_type_id,
- stage
- from sppr_request_financing
- where concost is not null and order_type_id != 70 and stage in (5, 6, 11, 12)
- )srf
- on srf.orginn = orgs.orginn
- inner join sppr_ref_customer_tbl src
- on src.inn = orgs.orginn
- ))
- group by fgrbsname) eco on eco.fgrbsname = w_o_eco.fgrbsname
- order by fgrbsname;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement