FreeOZ论坛
标题:
SQL 进行行间计算(累计余额)
[打印本页]
作者:
xblues
时间:
16-9-2010 21:07
提示:
作者被禁止或删除, 无法发言
标题:
SQL 进行行间计算(累计余额)
这个也要我想出来啦,我好厉害啊!
原表
SELECT ReportingDate, Complete
FROM CMGDM.drs.CampaignsSummary
复制代码
ReportingDate Complete
2010-08-18 00:00:00.000 0
2010-08-19 00:00:00.000 122
2010-08-20 00:00:00.000 151
2010-08-21 00:00:00.000 27
2010-08-23 00:00:00.000 14
2010-08-24 00:00:00.000 81
2010-08-25 00:00:00.000 80
2010-08-26 00:00:00.000 59
2010-08-27 00:00:00.000 156
2010-08-28 00:00:00.000 5
2010-08-30 00:00:00.000 64
2010-08-31 00:00:00.000 28
2010-09-01 00:00:00.000 37
2010-09-02 00:00:00.000 31
复制代码
==================================================================
计算累计值
SELECT ta.ReportingDate
, SUM(tb.Complete) AS RemainingRecord
FROM CMGDM.drs.CampaignsSummary AS ta
, CMGDM.drs.CampaignsSummary AS tb
WHERE ta.ReportingDate >= tb.ReportingDate
GROUP BY ta.ReportingDate
复制代码
ReportingDate RemainingRecord
2010-08-18 00:00:00.000 0
2010-08-19 00:00:00.000 122
2010-08-20 00:00:00.000 273
2010-08-21 00:00:00.000 300
2010-08-23 00:00:00.000 314
2010-08-24 00:00:00.000 395
2010-08-25 00:00:00.000 475
2010-08-26 00:00:00.000 534
2010-08-27 00:00:00.000 690
2010-08-28 00:00:00.000 695
2010-08-30 00:00:00.000 759
2010-08-31 00:00:00.000 787
2010-09-01 00:00:00.000 824
2010-09-02 00:00:00.000 855
复制代码
作者:
ubuntuhk
时间:
16-9-2010 23:07
这是MSSQL?
作者:
xblues
时间:
17-9-2010 00:19
提示:
作者被禁止或删除, 无法发言
对啊,我只会ms sql
欢迎光临 FreeOZ论坛 (https://hioz.im/ibbs/)
Powered by Discuz! X3.2