gpt4 book ai didi

sql - 如何使用 OVER 和 ORDER BY

转载 作者:行者123 更新时间:2023-12-02 20:53:05 28 4
gpt4 key购买 nike

我无法理解这段代码的错误。

代码:

SELECT
CariID, HesapID, BTrh, BCinsiID, BNo, Acklm, VdTrh, mTrh, BorcT, AlacakT,
SUM(BorcT) OVER (PARTITION BY CariID, HesapID ORDER BY BTrh, BNo, mTrh) AS TopBorcT,
SUM(AlacakT) OVER (PARTITION BY CariID, HesapID ORDER BY BTrh, BNo, mTrh ) AS TopAlacakT
FROM
tCariH

错误:

Msg 102, Level 15, State 1, Line 3

Incorrect syntax near 'order'.

最佳答案

使用类似 SUM 的聚合函数, you don't use ORDER BY in the OVER clause - 您只需要使用PARTITION功能。 ORDER用于排名功能:

Depending on the ranking, aggregate, or analytic function used with the OVER clause, <ORDER BY clause> and/or the <ROWS and RANGE clause> may not be supported.

只需修改以删除 ORDER在你的两个聚合中,你应该没问题。

关于sql - 如何使用 OVER 和 ORDER BY,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10028706/

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