25.sql 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. --25、샘籃데籃頓契냥굶槻樓
  2. ---뒈懇
  3. select t1.smonth,t1.sname,t1.cost_wuxian,
  4. t1.cost_hexin,t1.cost_wuxian_hexin,t2.site_count,
  5. t1.cost_wuxian_hexin/t2.site_count as site_cost
  6. from
  7. (select smonth,sname,stype,
  8. (column2+column3+column4+column5+column6+column7+column8+column9+column10+column11+column12+column13+column14+column15+column16+column17+column18) as cost_wuxian,
  9. (column19+column20+column21+column22+column23+column24+column25+column26) as cost_hexin,
  10. (column2+column3+column4+column5+column6+column7+column8+column9+column10+column11+column12+column13+column14+column15+column16+column17+column18+column19+column20+column21+column22+column23+column24+column25+column26) as cost_wuxian_hexin
  11. from sqmdb_cost.report50
  12. where sname in('柯소鏤_붉굇','鉗�_붉굇','해뽈돎_붉굇','벳덱_붉굇','饉憩_붉굇','괏땍_붉굇','蠟소왯_붉굇','넓돠_붉굇','읜렌_붉굇','꾕鹵_붉굇','뷜彊_붉굇','衿갛_붉굇')
  13. and smonth='202203') t1
  14. left join
  15. (select city_code,
  16. case when city_code=1301 then '柯소鏤_붉굇'
  17. when city_code=1302 then '鉗�_붉굇'
  18. when city_code=1303 then '해뽈돎_붉굇'
  19. when city_code=1304 then '벳덱_붉굇'
  20. when city_code=1305 then '饉憩_붉굇'
  21. when city_code=1306 then '괏땍_붉굇'
  22. when city_code=1307 then '蠟소왯_붉굇'
  23. when city_code=1308 then '넓돠_붉굇'
  24. when city_code=1309 then '꾕鹵_붉굇'
  25. when city_code=1310 then '읜렌_붉굇'
  26. when city_code=1311 then '뷜彊_붉굇'
  27. when city_code=1312 then '衿갛_붉굇'
  28. else '' end as city_name,
  29. count(*) as site_count
  30. from (select distinct eqp_sid,city_code from sqmdb_cost.equip where profession ='盧땡轟窟') a
  31. group by city_code) t2
  32. on t1.sname=t2.city_name
  33. ---貢목
  34. select t1.city_name,t1.area_name,t1.cost_wuxian,t1.cost_hexin,t1.cost_wuxian_hexin,t2.site_count,
  35. t1.cost_wuxian_hexin/t2.site_count as site_cost
  36. from
  37. (select fz.smonth,dg.city_name,dg.area_name,fz.cost_wuxian,fz.cost_hexin,fz.cost_wuxian_hexin from
  38. (select smonth,period_type,segment1_name,city_code,city_name,grid_code,grid_name,
  39. (column2+column3+column4+column5+column6+column7+column8+column9+column10+column11+column12+column13+column14+column15+column16+column17+column18) as cost_wuxian,
  40. (column19+column20+column21+column22+column23+column24+column25+column26) as cost_hexin,
  41. (column2+column3+column4+column5+column6+column7+column8+column9+column10+column11+column12+column13+column14+column15+column16+column17+column18+column19+column20+column21+column22+column23+column24+column25+column26) as cost_wuxian_hexin
  42. from sqmdb_cost.report49
  43. --where sname in('붉굇伽굶꼬','柯소鏤_붉굇','鉗�_붉굇','해뽈돎_붉굇','벳덱_붉굇','饉憩_붉굇','괏땍_붉굇','蠟소왯_붉굇','넓돠_붉굇','읜렌_붉굇','꾕鹵_붉굇','뷜彊_붉굇','衿갛_붉굇')
  44. where period_type='M' and grid_name!='북셕' and smonth='202203') fz
  45. join sqmdb_cost.dict_grid dg
  46. on fz.city_code=dg.grid_city_code::varchar and fz.grid_code=dg.grid_code::varchar) t1
  47. join
  48. (select dg.city_name,dg.area_name,sc.site_count from
  49. (select city_code,area_code,count(*) as site_count from
  50. (select distinct eqp_sid,city_code,area_code from sqmdb_cost.equip where profession ='盧땡轟窟') et
  51. group by city_code,area_code) sc
  52. join sqmdb_cost.dict_grid dg
  53. on sc.city_code=dg.city_code and sc.area_code=dg.area_code) t2
  54. on t1.city_name=t2.city_name and t1.area_name=t2.area_name
  55. order by t1.city_name,t1.area_name