0

有人能告诉我为什么当我为 [PropertyId] 添加额外的连接信息时返回 0 条记录吗?我知道这很简单,但是我不知所措。

declare @ViewId as int;

set @ViewId = 11;

with Views
as
(
    select [LiveWireView].[Id], [LiveWireView].[Name], [LiveWireView].[ParentId], [PropertyToViewMap].[PropertyId]
    from [LiveWireView]
    inner join [PropertyToViewMap] on [PropertyToViewMap].[ViewId] = [LiveWireView].[Id]
    where [LiveWireView].[Id] = @ViewId
    union all
    select [v].[Id], [v].[Name], [v].[ParentId], [p].[PropertyId]
    from [LiveWireView] v
    inner join [PropertyToViewMap] p on [p].[ViewId] = [v].[Id]
    inner join Views on Views.Id = v.ParentId
)

select [PropertyId] from Views;
4

1 回答 1

0

如果您添加了此联接:

inner join [PropertyToViewMap] p on [p].[ViewId] = [v].[Id]

并且不再获得结果,我认为说没有符合这些条件的记录是一样的。您可以通过将其转换为 aLEFT JOIN并查看是否为PropertyId

于 2012-09-06T20:53:06.390 回答