gpt4 book ai didi

sql-server - SQL Server 2008 R2 中的窗口函数问题

转载 作者:行者123 更新时间:2023-12-03 22:29:53 25 4
gpt4 key购买 nike

我在以下 SQL 脚本中遇到执行错误:

SELECT TOP 1 PERCENT
a.accode, a.voucherdate, a.credit, a.Debit,
SUM(a.Debit) OVER (ORDER BY [a.accode],[a.voucherdate]) AS rdr
FROM
VoucherMain AS a
ORDER BY
a.accode, a.voucherdate

错误信息

Incorrect syntax near 'order'

谁能告诉我我的语法有什么问题?

最佳答案

问题是您需要 SQL Server 2012 及更高版本。好的,我为 future 的访客添加了“及以上”,但比较 2008 OVER CLAUSE2012 OVER CLAUSE .

2008 版有这个重要说明:

When used in the context of a ranking window function, <ORDER BY
Clause>
can only refer to columns made available by the FROM clause. An integer cannot be specified to represent the position of the name or alias of a column in the select list. <ORDER BY Clause> cannot be used with aggregate window functions.

关于sql-server - SQL Server 2008 R2 中的窗口函数问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12686140/

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