我正在测试派生表查询。当我在查询下面运行时,它会显示错误。
`Invalid object name 'result'.`
我真的很惊讶。任何人都可以清楚我怀疑为什么会抛出这个奇怪的错误。
SELECT
*
FROM (SELECT
1 AS ID,
'Mike' AS Name) [result]
WHERE result.ID NOT IN (SELECT
ID
FROM [result]
WHERE Name = 'Mike')
答案 0 :(得分:0)
您无法使用该语法重用派生表 使用CTE(公用表表达式)。
with [result] as
(SELECT
1 AS ID,
'Mike' AS Name)
SELECT
*
FROM result
WHERE result.ID NOT IN (SELECT
ID
FROM [result]
WHERE Name = 'Mike')