回答

收藏

如何不按分组方式求和

技术问答 技术问答 207 人阅读 | 0 人回复 | 2023-09-14

这是我的问题。
8 c+ _# j5 y- h6 u8 RActual   Auction   Ammanat   id7000    500       1000      228,2297000         100        228,2297000          228,2295000                        我想要以下结果
+ G* k: D/ `, E& g" uActual   Auction   Ammanat   Remaining  id5000            5550      228,2297000          5550         228,2297000           550     550     228,2297000         550      5550                            在这里Remaining是(sum(auction)-actual)。
& p6 j# s" K2 D( R  V我正在使用PostgreSQL。但是,如果有人知道的话SQL Server解决方案,那就可以了。" K4 t) X# X: L' r" ~/ A; o* U
                                                               
' _- n4 p9 ?3 N& m; H    解决方案:                                                               
) [! ~# w- R% B7 r5 N/ |$ J) @                                                                您需要使用窗口功能-http://www.postgresql.org/docs/9.3/static/tutorial-
( W" B) A9 T/ w' I5 F$ j0 Uwindow.html
3 c% Y# v# h. L: X就像是:
& z, ~. s! ^' m, ~. `; w: y5 V(Sum(Auction) OVER ()) - actual AS Remaining
分享到:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则