oracle - 从具有空值的两个表中查找不匹配的记录
问题描述
我想从 table2 中找到不匹配的 val 记录。它也有空值
表格1
id val
1 10
2 20
3 30
4 null
表2
id val
1 10
3 30
4 null
对于上面的例子,它应该返回 20。
解决方案
简单的存在结构在这里工作
with tmp1 as(
select 1 id, 10 val from dual
union
select 2 id, 20 val from dual
union
select 3 id, 30 val from dual
union
select 4 id, null val from dual),
tmp2 as(
select 1 id, 10 val from dual
union
select 3 id, 30 val from dual
union
select 4 id, null val from dual)
select
tmp1.*
from
tmp1
where
not exists(
select
null
from
tmp2
where
nvl(tmp1.val,-1) = nvl(tmp2.val,-1))
推荐阅读
- android - 第一次使用反应。Rss显示问题
- python - Pandas 将组结果的所有列汇总为一个结果
- r - 向量 R 中的结构数
- spring-boot - 如何将百里香表单数据发布到控制器
- java - 颤振医生--android-licenses线程“主”java.lang.NoClassDefFoundError中的异常:javax/xml/bind/annotation/XmlSchema
- laravel - 问题 'SQLSTATE[42S02]: 未找到基表或视图
- oracle - Spring JDBC Oracle Session 改线程下
- ruby-on-rails - 我应该如何处理这个异常?
- angular - 自动调整列标题的大小Angular slickgrid
- graphql - 如何在一个 GraphQL 请求中返回多个结果?