在这个复杂的情况下寻求帮助。
我有三个名为Interchange
,Driver
和Application
来自APPLICATION表的所有SKU,它们存在于Interchange表中,其Check作为'REP',可用于名为'Baseline'的列和Correspondance NewSKU,其中Newline存在于驱动程序表中
表格: -
DECLARE @Interchange TABLE
(
SKU VARCHAR (50),
CHECKS VARCHAR (50),
NewSKU VARCHAR (50)
)
INSERT @Interchange
SELECT 'AEM41-1408DS', 'Bridgestone', '41-1408DS' UNION ALL
SELECT 'AEM41-1408DS', 'REP', 'AEM21-203DK'
DECLARE @Driver TABLE
(
BaseLine VARCHAR (50),
NewLine VARCHAR (50)
)
INSERT @Driver
SELECT 'Cold Air Intake', 'Air Filter%'
DECLARE @APPLICATION TABLE
(
SKU VARCHAR (50),
line VARCHAR (50)
)
INSERT @APPLICATION
SELECT 'AEM41-1408DS', 'Cold Air Intake' UNION ALL
SELECT 'AEM41-1408DS', 'Cold Air Intake' UNION ALL
SELECT 'AEM41-1408DS', 'Cold Air Intake' UNION ALL
SELECT 'AEM41-1408DS', 'Cold Air Intake' UNION ALL
SELECT 'AEM21-203DK', 'Air Filter High'
任何人都可以为这个复杂的场景建议t-sql查询吗?
答案 0 :(得分:0)
据我了解你的评论,我已经为你写了下面的查询,如果它不符合你的要求,那么请分享样本输出。
select A.* from @APPLICATION A
where exists (select sku from @Interchange where A.SKU = SKU)
AND EXISTS (SELECT baseLine from @Driver where BaseLine = A.line)