17.sql 574 B

12345678910111213141516
  1. --17﹜誧歙蚾儂蹋煤
  2. ---華庈
  3. select fz.smonth,fz.sname,fz.cost_liao,fm.order_num,
  4. fz.cost_liao/fm.order_num as cost_order
  5. from
  6. (select smonth,sname,cost_liao from sqmdb_cost.chengben_shengnei cs
  7. where stype='華庈' and smonth='202203') fz
  8. join
  9. (select b.city_code,b.city_pro,a.order_num from
  10. (select smonth,city_code,city_name,sum(order_num)/10000 as order_num
  11. from sqmdb_cost.zhuangji z where smonth='202203'
  12. group by smonth,city_code,city_name) a
  13. join
  14. (select distinct city_code,city_pro from sqmdb_cost.dict_grid dg) b
  15. on a.city_code=b.city_code) fm
  16. on fz.sname=fm.city_pro