同步选择的投影
我想在另一个 select 语句的投影中使用表别名,如下所示:
SELECT [ID]
,[Name]
,CASE WHEN 'reptile' IN
(SELECT [Type] FROM dbo.Pets [S] INNER JOIN [P] ON S.People_ID = P.ID)
THEN 1 ELSE 0 END [HasReptile]
FROM People [P]
在投影中有一个 select 语句,它试图使用表别名 [P]。显然这是不合法的。如何在不使用两个单独的查询的情况下实现我的目标?
实际上,我的查询是“对任何拥有“爬行动物”类型宠物的人显示“1”。
我正在使用 SQL Server 2008。
I would like to use a table alias within the projection of another select statement, like this:
SELECT [ID]
,[Name]
,CASE WHEN 'reptile' IN
(SELECT [Type] FROM dbo.Pets [S] INNER JOIN [P] ON S.People_ID = P.ID)
THEN 1 ELSE 0 END [HasReptile]
FROM People [P]
Within the projection there is a select statement, which is trying to use the table alias [P]. Evidentally this is not legal. How can I achieve my goal without using two separate queries?
In effect, my query is saying "show '1' for any person who owns a pet of type 'reptile'.
I am using SQL Server 2008.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)