select *from table1 t1
left join table2 t3
on t1.客户ID=t3.客户ID
and t1.客户名称=t3.客户名称
and t1.截止时间=add_months(t3.截止时间,3)and t3.截止时间=add_months(substring(cast(date_add(TRUNC(from_unixtime(unix_timestamp('${V_DATE}','yyyy-MM-dd'),'yyyy-MM-dd'),'Q'),-1)as string),1,10),-3)
where not exists (select 1from(select count(1) over()as count_1,
t.*from table2 t
where 截止时间=substring(cast(date_add(TRUNC(from_unixtime(unix_timestamp('${V_DATE}','yyyy-MM-dd'),'yyyy-MM-dd'),'Q'),-1)as string),1,10)) t2
where t1.客户ID=t2.客户ID
and t1.客户名称=t2.客户名称
and t1.截止时间 = t2.截止时间
and count_1=0