insert overwrite table table2 select d.nsr from (select a.nsr_id as nsr from nsrxx a inner join zzsfp b on b.gf_id = a.nsr_id group by a.nsr_id) as d where nsr not in (select a.nsr_id from nsrxx a inner join zzsfp b on b.xf_id = a.nsr_id group by a.nsr_id);