如何不按分组进行求和 [英] How to make a SUM without group by

查看:89
本文介绍了如何不按分组进行求和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的问题。

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

剩余(实际总和(拍卖))

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

I am using PostgreSQL. But if anyone know solution in SQL Server, it will be OK.

推荐答案

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

You need a to use a window function - http://www.postgresql.org/docs/9.3/static/tutorial-window.html

类似的东西:

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

这篇关于如何不按分组进行求和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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