gpt4 book ai didi

sql - "Incorrect syntax"使用公用表表达式时

转载 作者:行者123 更新时间:2023-12-03 23:31:04 28 4
gpt4 key购买 nike

WITH list_dedup (Company, duplicate_count) AS
(
SELECT
*,
ROW_NUMBER() OVER (PARTITION BY Company ORDER BY Email) AS 'RowNumber'
FROM
Travels
)

错误 :

Msg 102, Level 15, State 1, Line 7
Incorrect syntax near ')'.

最佳答案

您缺少公用表表达式的最终选择( CTE 的定义之后):

WITH list_dedup  (Company,duplicate_count) As
(
select *,
ROW_NUMBER() OVER (PARTITION BY Company ORDER by Email) As "RowNumber"
From Travels
)
select *
from list_dedup;

但这不会因为 CTE 被定义为具有 两个 列(通过 WITH list_dedup (Company,duplicate_count) ),但您在 CTE 中的选择至少返回三列(公司、电子邮件、行号)。您需要调整 CTE 的列定义,或者完全忽略它:
WITH list_dedup As
(
select *,
ROW_NUMBER() OVER (PARTITION BY Company ORDER by Email) As "RowNumber"
From Travels
)
select *
from list_dedup;
As "RowNumber"在定义列列表时,内部选择也没有意义,因为 CTE 定义定义了列名。 CTE 内部使用的任何别名在其外部都将不可见(如果 CTE 列在 with .. (...) as 部分中指定)。

关于sql - "Incorrect syntax"使用公用表表达式时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40072450/

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