SQL Server 2008 R2 中的窗口函数问题 [英] Issue with Window Function in SQL Server 2008 R2

查看:43
本文介绍了SQL Server 2008 R2 中的窗口函数问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I get an execution error in following SQL script:

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

错误信息

'order' 附近的语法不正确

Incorrect syntax near 'order'

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

Can anyone tell me what's wrong with my syntax?

推荐答案

问题是你需要 SQL Server 2012 及更高版本.好的,我为未来的访问者添加了及以上",但比较 2008 OVER CLAUSE 带有 2012 年结束条款.

The problem is that you need SQL Server 2012 and above. Okay, I added the "and above" for future visitors, but compare 2008 OVER CLAUSE with 2012 OVER CLAUSE.

2008 版有以下重要说明:

The 2008 version has this important note:

在排名窗口函数的上下文中使用时, 只能引用由 FROM 子句提供的列.不能指定整数来表示名称的位置或选择列表中列的别名. 不能与聚合窗口函数一起使用.

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 2008 R2 中的窗口函数问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆