以上为测试数据,两张临时表的数据完全一致,来源于同一张表的两个分区中

需要在20230206的分区中判断数据是否与20230205一致,若一致,则不显示行

通过以下查询语句进行查询后,结果20230206的数据仍然会照常显示出来

with table1 as

(select

a.name , -- 名称

a.code , -- 编码

a.login_id , -- 帐号

a.email , -- 邮箱

a.is_on_job , -- 是否在岗、在职标示

a.mobile , -- 移动电话

b.post_name, --岗位名称

b.post_record_id, --岗位记录

b.empl_rcd,

b.effdt,

b.effseq

from ods_emp_i_d a

left join ods_emp_post_i_d b

on b.dt = '2023-02-05' and b.is_deleted=0 and b.flag = 1 and b.emp_code = a.code

where a.dt = '2023-02-05' and a.is_deleted=0 and a.code = '123456'

order by a.code,b.updated_time desc)

,

table2 as(

select

a.name , -- 名称

a.code , -- 编码

a.login_id , -- 帐号

a.email , -- 邮箱

a.is_on_job , -- 是否在岗、在职标示--

a.mobile , -- 移动电话

b.post_name, --岗位名称

b.post_record_id, --岗位记录

b.empl_rcd,

b.effdt,

b.effseq

from ods_emp_i_d a

left join ods_emp_post_i_d b

on b.dt = '2023-02-06' and b.is_deleted=0 and b.flag = 1 and b.emp_code = a.code

where a.dt = '2023-02-06' and a.is_deleted=0 and a.code = '123456'

order by a.code,b.updated_time desc)

select * from table2 t

where NOT exists(select 1 from table1 c

where nvl(c.code,'') = nvl(t.code,'')

and nvl(c.post_record_id,'') = nvl(t.post_record_id,'')

and nvl(c.empl_rcd,'') = nvl(t.empl_rcd,'')

and nvl(c.effdt,'') = nvl(t.effdt,'')

and nvl(c.effseq,'') = nvl(t.effseq,'')

)

解决方案:取消使用NOT EXISTS来过滤数据

修改为左连接的方式,只取20230206的数据

参考来源于https://blog.csdn.net/qq_38238956/article/details/124778421

成功解决。

请问下有没有大神指导一下,为什么通过not exists,将字段为空的数据用NVL转掉后,仍然无法正常过滤数据

精彩内容

评论可见,请评论后查看内容,谢谢!!!
 您阅读本篇文章共花了: