update npas.meta_localinfo e set city_key = d.city_key, city=d.city from ( select a.*,c.city_key from ( select site_planning_id,substr(area, 0, 3) as city from (select site_planning_id,area from npas.meta_localinfo where city_key is null and area is not null and area !='' ) as b ) as a left JOIN npas.dim_city c on c.city=a.city ) as d where e.city_key is null and e.site_planning_id=d.site_planning_id