gpt4 book ai didi

sql-server - SQL WHERE.. IN 子句多列

转载 作者:行者123 更新时间:2023-12-01 16:33:00 25 4
gpt4 key购买 nike

我需要在 SQL Server 中实现以下查询:

select *
from table1
WHERE (CM_PLAN_ID,Individual_ID)
IN
(
Select CM_PLAN_ID, Individual_ID
From CRM_VCM_CURRENT_LEAD_STATUS
Where Lead_Key = :_Lead_Key
)

但是 WHERE..IN 子句只允许 1 列。如何将 2 列或更多列与另一个内部 SELECT 进行比较?

最佳答案

您需要使用 WHERE EXISTS 语法。

SELECT *
FROM table1
WHERE EXISTS (SELECT *
FROM table2
WHERE Lead_Key = @Lead_Key
AND table1.CM_PLAN_ID = table2.CM_PLAN_ID
AND table1.Individual_ID = table2.Individual_ID)

关于sql-server - SQL WHERE.. IN 子句多列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1136380/

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