01.sql 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. --01、网运成本占收比(集团口径)
  2. ---北10
  3. select
  4. smonth,
  5. sname,
  6. column6 as cost_with_rengong,
  7. column10 as cost_no_rengong,
  8. column14 as income,
  9. column6/column14 rate_with_rengong,
  10. column10/column14 rate_no_rengong
  11. --column17 as 网运成本占收比(含人工),
  12. --column20 as 网运成本占收比(不含人工)
  13. from sqmdb_cost.report50003
  14. where sname in('北京','天津','河北','山西','内蒙古','辽宁','吉林','黑龙江','山东','河南')
  15. and smonth='202203'
  16. ---地市
  17. select
  18. a.smonth,
  19. a.sname,
  20. a.cost_total,
  21. b.income_year, --本年收入累计,
  22. case when b.income_year=0 then null else a.cost_total/b.income_year end as cost_rate--网运成本占收比(集团口径)
  23. --c.city_code
  24. from
  25. (select '202203' as smonth,sname,
  26. sum(column1)/10000 as cost_total--成本合计(包含人工)
  27. from sqmdb_cost.report50 where smonth between '202201' and '202203' group by sname) a
  28. left join
  29. (select report_id,smonth,sname,stype,column4 as income_year from sqmdb_cost.report80040) b
  30. on a.smonth=b.smonth and a.sname=b.sname
  31. left join
  32. (select distinct city_code,city_pro from sqmdb_cost.dict_grid) c
  33. on a.sname=c.city_pro
  34. where a.sname in ('石家庄_河北','唐山_河北','秦皇岛_河北','邯郸_河北','邢台_河北','保定_河北','张家口_河北','承德_河北','廊坊_河北','沧州_河北','衡水_河北','雄安_河北')
  35. and a.smonth='202203'
  36. ---网格(网格数据缺少分母)-目前只有分子
  37. select smonth,segment1_name,city_name,grid_name,
  38. column1 as cost_total
  39. from sqmdb_cost.report49