有3个表相同的列但具有不同的值..结果应该只是在结果集中打印相同的组合
示例 表a
col x col y
23 a01
23 a02
24 a11
25 a12
表b
col x col y
23 a10
23 a02
24 a11
25 a12
表c
col x col y
23 a01
23 a02
24 a11
25 a12
希望结果为
col x col y
24 a11
25 a12
请帮助我们获取查询
答案 0 :(得分:1)
不熟悉ETL,但如果它只是普通的SQL,它应该是这样的:
select a.*
from a
inner join b on a.x = b.x and a.y=b.y
inner join c on a.x = c.x and a.y=c.y
答案 1 :(得分:0)
如果要在不同的表中标识相同的行,可以使用INTERSECT运算符
WITH CTE_T1 AS
(
SELECT [X] ,[Y]
FROM
(VALUES
(23, 'a01')
,(23, 'a02')
,(24, 'a11')
,(25, 'a12')
) T1([X],[Y])
),
CTE_T2 AS
(
SELECT [X] ,[Y]
FROM
(VALUES
(23, 'a10')
,(23, 'a20')
,(24, 'a11')
,(25, 'a12')
) T2([X],[Y])
),
CTE_T3 AS
(
SELECT [X] ,[Y]
FROM
(VALUES
(23, 'a40')
,(23, 'a50')
,(24, 'a11')
,(25, 'a12')
) T3([X],[Y])
)
SELECT [X],[Y] FROM CTE_T1
INTERSECT
SELECT [X],[Y] FROM CTE_T2
INTERSECT
SELECT [X],[Y] FROM CTE_T3
此语句产生以下结果
X Y
----------- ----
24 a11
25 a12
(2 row(s) affected)