gpt4 book ai didi

sql - 如何在没有分组依据的情况下进行求和

转载 作者:行者123 更新时间:2023-11-29 11:15:18 25 4
gpt4 key购买 nike

这是我的问题..

Actual   Auction   Ammanat   id
7000 500 100 228,229
7000 100 100 228,229
7000 900 100 228,229
5000 0 0 230

我想要下面给出的结果

Actual   Auction   Ammanat   Remaining  id
7000 500 100 5550 228,229
7000 100 100 5550 228,229
7000 900 100 5550 228,229
5000 0 0 5000 230

这里,剩余(sum(auction)-actual)

我正在使用 PostgreSQL。但是,如果有人知道 SQL Server 中的解决方案,那就没问题了。

最佳答案

您需要使用窗口函数 - http://www.postgresql.org/docs/9.3/static/tutorial-window.html

类似于:

(Sum(Auction) OVER ()) - actual AS Remaining

关于sql - 如何在没有分组依据的情况下进行求和,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19271646/

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