合同校验_正向.sql 974 B

123456789101112131415161718192021
  1. --数据校验 合同系统 <- 合同索引 <- 局站表
  2. with vt as (select a.sid,a.sname,a.cname,a.cfname,a.cbzx,a.yuezujin,
  3. b.city_name,b.city_code,b.district_code,b.hetong_sid,b.station_sid as station_sid_i,
  4. c.station_sid as station_sid_s,
  5. (case
  6. when b.hetong_sid is not null and c.station_sid is not null then '有合同有局站'--'合同系统有,资源系统没'
  7. when b.hetong_sid is null or (b.hetong_sid is not null and c.station_sid is null) then '有合同无局站'--'合同系统有,资源系统没有'
  8. else '其他'
  9. end) as check_result
  10. from sqmdb_cost.hetong2 a
  11. left join sqmdb_cost.station_hetong b on a.sid=b.hetong_sid||E'\t'
  12. left join sqmdb_cost.station2 c on b.station_sid=c.station_sid)
  13. select t1.*,t2.city_code from
  14. (select substr(cname,5,length(cname)-7) as city,sid,sname,yuezujin as cost_hetong,cbzx
  15. from vt where check_result='有合同无局站') t1
  16. left join
  17. (select distinct city_code,city_sname from sqmdb_cost.dict_grid) t2
  18. on t1.city=t2.city_sname
  19. order by t2.city_code,t1.cost_hetong desc