gpt4 book ai didi

sql-server - SQLServer 在单个语句中编写 union

转载 作者:行者123 更新时间:2023-12-03 03:52:34 25 4
gpt4 key购买 nike

我有如下查询:



SELECT * FROM [PMDB_DEV].[dbo].[TRSRCFIN]
WHERE proj_id = 167592
AND taskrsrc_id NOT IN
(
SELECT taskrsrc_id FROM [PMDB_ARC].[dbo].[TRSRCFIN_TEST]
WHERE proj_id = 167592
)
UNION
SELECT * FROM [PMDB_DEV].[dbo].[TRSRCFIN]
WHERE proj_id = 167592
AND fin_dates_id NOT IN
(
SELECT fin_dates_id FROM [PMDB_ARC].[dbo].[TRSRCFIN_TEST]
WHERE proj_id = 167592
)

基本上,查询返回taskrsrc_id或fin_dates_id不应出现在子查询数据中的所有行。

我可以在不使用 UNION 的情况下做到这一点吗?

谢谢,马赫什

最佳答案

select  * 
from [PMDB_DEV].[dbo].[TRSRCFIN] t1
where proj_id = 167592
and not exists
(
select *
from [PMDB_ARC].[dbo].[TRSRCFIN_TEST] t2
where t2.proj_id = t1.proj_id
and (
t1.taskrsrc_id = t2.taskrsrc_id
or
t1.fin_dates_id = t2.fin_dates_id
)
)

关于sql-server - SQLServer 在单个语句中编写 union,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9704785/

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