gpt4 book ai didi

sql - 如何用等效的 LEFT OUTER JOIN 替换复杂的 SQL MINUS 查询

转载 作者:行者123 更新时间:2023-12-04 18:42:58 42 4
gpt4 key购买 nike

试图弄清楚如何用等效的左外连接替换以下内容:

select distinct(a.some_value)
from table_a a, table_b b
where a.id = b.a_id
and b.some_id = 123
and b.create_date < '2014-01-01'
and b.create_date >= '2013-12-01'
MINUS
select distinct(a.some_value)
from table_a a, table_b b
where a.id = b.a_id
and b.some_id = 123
and b.create_date < '2013-12-01'

不能做“NOT IN”,因为第二个查询有太多数据。

最佳答案

SELECT * FROM
(
select distinct(a.some_value)
from table_a a, table_b b
where a.id = b.a_id
and b.some_id = 123
and b.create_date < '2014-01-01'
and b.create_date >= '2013-12-01'
) x
LEFT JOIN
(
select distinct(a.some_value)
from table_a a, table_b b
where a.id = b.a_id
and b.some_id = 123
and b.create_date < '2013-12-01'
) y
ON
x.some_value = y.some_value
WHERE
y.some_value IS NULL

关于sql - 如何用等效的 LEFT OUTER JOIN 替换复杂的 SQL MINUS 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21009748/

42 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com