问题描述
您需要使用窗口功能-http://www.postgresql.org/docs/9.3/static/tutorial- window.html
就像是:
(Sum(Auction) OVER ()) - actual AS Remaining
解决方法
这是我的问题。
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
在这里Remaining
是(sum(auction)-actual)
。
我正在使用PostgreSQL。但是,如果有人知道SQL Server中的解决方案,那就可以了。