gpt4 book ai didi

sql - "Incorrect syntax near the keyword ' WHERE '"在 SQL Server 中的 from 子句

转载 作者:行者123 更新时间:2023-12-04 14:17:59 27 4
gpt4 key购买 nike

SELECT 
[EmpNum], [EmpEmergencyContact], [Relation], [PhType], [Phone]
FROM
(SELECT
[EmpNum], [EmpEmergencyContact], [Relation], [PhType], [Phone]
FROM [EMERGENCY_CONTACT])

一个简单的查询,我有一个 SELECT FROM内的声明子句返回错误:

Incorrect syntax near ')'

最佳答案

您需要在 from 语句上放置别名。

所以改变这个:

   FROM [EMERGENCY_CONTACT]
)

对此:
   FROM [EMERGENCY_CONTACT]
) AS tbl

像这样:
SELECT [EmpNum], [EmpEmergencyContact], [Relation], [PhType], [Phone] 
FROM (
SELECT [EmpNum], [EmpEmergencyContact], [Relation], [PhType], [Phone]
FROM [EMERGENCY_CONTACT]
) AS tbl

更安全的是在列上使用别名,如下所示:
SELECT 
tbl.[EmpNum],
tbl.[EmpEmergencyContact],
tbl.[Relation],
tbl.[PhType],
tbl.[Phone]
FROM (
SELECT [EmpNum], [EmpEmergencyContact], [Relation], [PhType], [Phone]
FROM [EMERGENCY_CONTACT]
) AS tbl

关于sql - "Incorrect syntax near the keyword ' WHERE '"在 SQL Server 中的 from 子句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25113201/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com