我正在使用流分析的 T-SQL 对流输入和参考数据输入进行完全外部联接。
我已经尝试了以下查询,但我不断收到错误消息“当加入流和参考数据时,参考数据必须在右侧”。
我想做两者的完全外连接 - 如果参考数据永远不会在左侧,我该怎么做?
With leftJoin AS (
SELECT SA.[InputID], RD.[InputID]
FROM StreamData AS SA
LEFT JOIN ReferenceData AS RD
ON SA.[InputID] = RD.[InputID]
),
rightJoin AS (
SELECT SA.[InputID], RD.[InputID]
FROM ReferenceData AS RD -- Causes the error 'cause it should be on the right
LEFT JOIN StreamData AS SA
ON SA.[InputID] = RD.[InputID]
)
SELECT *
INTO [StorageTable]
FROM leftJoin
UNION
SELECT *
FROM rightJoin
我的预期输出是这样的:
SA.[InputID] | RD.[InputID]
------------------------------
1 | 1
2 | null
null | 3
4 | 4