作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我无法理解 Oracle 返回这个奇怪结果的原因。
我觉得代码真的很清楚。
我期待
无条件 =(在 OUTER JOIN cond 中不为 null)+(在 OUTER JOIN cond 中为 null)
因为我将外部连接右表列中的 IS NULL/IS NOT NULL 解释为 EXISTS/NOT EXISTS 条件。
为什么我错了?
DESCRIPTION COUNT(1)
---------------------------------- ----------
No condition 6403
is NOT null in OUTER JOIN cond 6403
is not null in where cond 6401
is null in OUTER JOIN cond 6247
is null in where cond 2
proof flh_id_messaggio is not null 0
proof flh_stato is not null 0
SELECT 'is null in OUTER JOIN cond ' description, count(1)
FROM netatemp.TMP_BACKLOG_NOBILLING2013 t
LEFT OUTER JOIN
eni_flussi_hub c ON
c.flh_id_messaggio = t.flh_id_messaggio
AND c.flh_stato is null
WHERE 1 = 1
And t.flh_stato = 'PA'
AND t.OWNER = 'ETL'
UNION
SELECT 'is NOT null in OUTER JOIN cond ' description, count(1)
FROM netatemp.TMP_BACKLOG_NOBILLING2013 t
LEFT OUTER JOIN
eni_flussi_hub c ON
c.flh_id_messaggio = t.flh_id_messaggio
AND c.flh_stato is not null
WHERE 1 = 1
And t.flh_stato = 'PA'
AND t.OWNER = 'ETL'
UNION
SELECT 'is null in where cond ' description, count(1)
FROM netatemp.TMP_BACKLOG_NOBILLING2013 t
LEFT OUTER JOIN
eni_flussi_hub c ON
c.flh_id_messaggio = t.flh_id_messaggio
WHERE 1 = 1
And t.flh_stato = 'PA'
AND t.OWNER = 'ETL'
AND c.flh_stato is null
UNION
SELECT 'is not null in where cond ' description, count(1)
FROM netatemp.TMP_BACKLOG_NOBILLING2013 t
LEFT OUTER JOIN
eni_flussi_hub c ON
c.flh_id_messaggio = t.flh_id_messaggio
WHERE 1 = 1
And t.flh_stato = 'PA'
AND t.OWNER = 'ETL'
AND c.flh_stato is not null
UNION
SELECT 'No condition' description, count(1)
FROM netatemp.TMP_BACKLOG_NOBILLING2013 t
LEFT OUTER JOIN
eni_flussi_hub c ON
c.flh_id_messaggio = t.flh_id_messaggio
WHERE 1 = 1
And t.flh_stato = 'PA'
AND t.OWNER = 'ETL'
UNION select 'proof flh_stato is not null' description, count(1)
from eni_flussi_hub
where flh_stato is null
UNION select 'proof flh_id_messaggio is not null' description, count(1)
from eni_flussi_hub
where flh_id_messaggio is null
最佳答案
EXISTS
/NOT EXISTS
通过放置 NULL
获得等效查询条件在 WHERE
条款,不在 OUTER JOIN
中条款。顺便说一下,这是我们从您的结果中观察到的:
No condition 6403
is not null in where cond 6401
is null in where cond 2
OUTER JOIN
中时条款,你告诉 Oracle
OUTER JOIN
你的主表来了
行子集 从连接表。
c.flh_stato
永远不会为空,条件是多余的,我们得到与无条件查询相同的结果:
No condition 6403
is NOT null in OUTER JOIN cond 6403
c.flh_stato IS NULL
在join子句中,我们将主表连接到一个空的结果集,这样我们就得到了主表每一行的一行(我们在这种情况下扣除了主表有6247行):
is null in OUTER JOIN cond 6247
关于Oracle 左外连接在 JOIN vs WHERE 条件中为空(示例),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17192527/
我是一名优秀的程序员,十分优秀!