Advertisement
Guest User

Untitled

a guest
Apr 21st, 2015
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.67 KB | None | 0 0
  1. select w_o_eco.*, eco.eco from (select fgrbsname,
  2. sum(
  3. case when number_ in (5, 6, 11, 12) then price else 0 end) / 1000000 as yearly,
  4. sum(
  5. case when number_ in (5, 6, 11, 12) and uoplacing = 1 then price else 0 end) / 1000000 as yearlyuo,
  6. sum(
  7. case when number_ in (11, 12) then price else 0 end) / 1000000 as yearlyisp,
  8. sum(
  9. case when number_ in (11, 12) and uoplacing = 1 then price else 0 end) / 1000000 as yearlyispuo,
  10. sum(
  11. case when number_ in (5, 6, 11, 12) and extract( month from plannedplacementdate) = 4 then price else 0 end) / 1000000 as monthly,
  12. sum(
  13. case when number_ in (11, 12) and extract( month from plannedplacementdate) = 4 then price else 0 end) / 1000000 as monthlyisp,
  14. sum(
  15. case when number_ in (6) and extract( month from plannedplacementdate) = 4 then price else 0 end) / 1000000 as monthlypalce,
  16. sum(
  17. case when number_ in (5, 6, 11, 12) and extract( month from plannedplacementdate) = 5 then price else 0 end) / 1000000 as nextmonthly
  18. from sppr_plan_placement
  19. where fgrbsname not in ('Уполномоченный по защите прав предпринимателей в Санкт-Петербурге', 'Уполномоченный по правам ребенка в Санкт-Петербурге', 'Уполномоченный по правам человека в Санкт-Петербурге', 'Уставный суд Санкт-Петербурга', 'Контрольно-счётная палата Санкт-Петербурга', 'Санкт-Петербургская избирательная комиссия', 'Законодательное Собрание Санкт-Петербурга')
  20. group by fgrbsname) w_o_eco full outer join
  21. (select fgrbsname,
  22. sum(nmc) nmc,
  23. sum(sum_) concost,
  24. sum(eco) eco
  25. from (
  26. (select src.fgrbsname fgrbsname,
  27. flotnmc nmc,
  28. sum_,
  29. case when (flotnmc - sum_) > 0 then (flotnmc - sum_) else 0 end / 1000000 eco
  30. from
  31. (select ldm.uuid,
  32. ldm.offer,
  33. ldm.joflag,
  34. case when joflag = 0 then ldm.customer else tb.parentid end org,
  35. ldm.flotnmc,
  36. cs.sum_
  37. from sppr_lot_data_nmc ldm
  38. inner join
  39. (select sc.lot,
  40. sum(sc.contractcost)sum_
  41. from sppr_contract sc
  42. inner join site_contracts_req_2015 r15
  43. on r15.uuid = sc.contract
  44. inner join sppr_ref_order_type srot
  45. on srot.fordertypeuuid = sc.ordertype
  46. where srot.fcompetitionflag = 1
  47. group by sc.lot
  48. )cs on cs.lot = ldm.uuid
  49. inner join tbl_bo tb
  50. on tb.uuid = ldm.offer
  51. inner join
  52. (select distinct dor.offer uuid
  53. from sppr_plan_placement spp
  54. inner join dwh_offer_request_t dor
  55. on dor.request = spp.reqid
  56. where number_ in (5, 6, 11, 12)
  57. )offer on offer.uuid = ldm.offer
  58. )lot
  59. inner join sppr_ref_customer_tbl src
  60. on src.orgid = lot.org
  61. where src.fgrbsname not in ('Уполномоченный по защите прав предпринимателей в Санкт-Петербурге', 'Уполномоченный по правам ребенка в Санкт-Петербурге', 'Уполномоченный по правам человека в Санкт-Петербурге', 'Уставный суд Санкт-Петербурга', 'Контрольно-счётная палата Санкт-Петербурга', 'Санкт-Петербургская избирательная комиссия', 'Законодательное Собрание Санкт-Петербурга')
  62. )
  63. union all
  64. (select src.fgrbsname,
  65. nvl(srf.nmc, 0) nmc,
  66. nvl(srf.concost, 0) concost,
  67. case when (srf.nmc - srf.concost) > 0 then (srf.nmc - srf.concost) else 0 end / 1000000 eco
  68. from
  69. (select distinct orginn from sppr_request_financing
  70. ) orgs
  71. left join
  72. (select distinct lot_id,
  73. nmc,
  74. concost,
  75. orginn,
  76. order_type_id,
  77. stage
  78. from sppr_request_financing
  79. where concost is not null and order_type_id != 70 and stage in (5, 6, 11, 12)
  80. )srf
  81. on srf.orginn = orgs.orginn
  82. inner join sppr_ref_customer_tbl src
  83. on src.inn = orgs.orginn
  84. ))
  85. group by fgrbsname) eco on eco.fgrbsname = w_o_eco.fgrbsname
  86. order by fgrbsname;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement