chengben_quzhun_2_city.sql 1.0 KB

123456789101112131415161718192021
  1. ---2.有合同无局站
  2. ---chengben_quzhun_2_city_202203.csv
  3. with vt as (select a.sid,a.sname,a.cname,a.cfname,a.cbzx,a.yuezujin,
  4. b.city_name,b.city_code,b.district_code,b.hetong_sid,b.station_sid as station_sid_i,
  5. c.station_sid as station_sid_s,
  6. (case
  7. when b.hetong_sid is not null and c.station_sid is not null then '有合同有局站'--'合同系统有,资源系统没'
  8. when b.hetong_sid is null or (b.hetong_sid is not null and c.station_sid is null) then '有合同无局站'--'合同系统有,资源系统没有'
  9. else '其他'
  10. end) as check_result
  11. from sqmdb_cost.hetong_new a
  12. left join sqmdb_cost.station_hetong b on a.sid=b.hetong_sid
  13. left join sqmdb_cost.station3 c on b.station_sid=c.station_sid)
  14. select '202204' as sdate,t1.*,t2.city_code*100 as city_code from
  15. (select substr(cname,5,length(cname)-7) as city,sid,sname,yuezujin as cost_hetong,cbzx
  16. from vt where check_result='有合同无局站') t1
  17. left join
  18. (select distinct city_code,city_sname from sqmdb_cost.dict_grid) t2
  19. on t1.city=t2.city_sname
  20. where t2.city_code is not null
  21. order by t2.city_code,t1.cost_hetong desc