我需要在 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 进行比较?
您可以从子查询创建派生表,并将 table1 连接到该派生表:
select * from table1 LEFT JOIN ( Select CM_PLAN_ID, Individual_ID From CRM_VCM_CURRENT_LEAD_STATUS Where Lead_Key = :_Lead_Key ) table2 ON table1.CM_PLAN_ID=table2.CM_PLAN_ID AND table1.Individual=table2.Individual WHERE table2.CM_PLAN_ID IS NOT NULL