我已经阅读了关于累积和的一些帖子,但是我一直在努力与SUM OVER
或其他累积和,加入相同的数据使用< =内部的一部分加入,所以我正在寻找一些澄清。SQL Server多个累积总和(2012或更高版本)
我从财务数据以下列:
AccountID,
FiscalYear,
FiscalQuarter,
FiscalPeriod,
PeriodType (we report on calendar and fiscal periods),
CurrencyType (source or functional currency),
DataSet (actual or budgeted data),
Currency (the currency of the transaction,
PeriodAmount
此信息目前期行格式总结,所以我工会的数据一起得到它以表格格式,然后尝试获得运行累计季度和年度的总计。例如:
如果我的数据是(现在我假定货币和其他领域不apearring是相同的,但它们可能会有所不同):
ACCTID FYear FQuarter FPeriod PAmount
123 2015 1 1 $100
123 2015 1 2 $100
123 2015 1 3 $100
123 2015 2 4 $100
我的数据的结果我想应该是:
123, 2015, 1, 1, $100, $100 (cumulative quarter), $100 (cumulative year)
123, 2015, 1, 2, $100, $200 (cumulative quarter), $200 (cumulative year)
123, 2015, 1, 3, $100, $300 (cumulative quarter), $300 (cumulative year)
123, 2015, 2, 4, $100, $100 (cumulative quarter), $400 (cumulative year)
它似乎想,当我做SUM OVER(PARTITION BY AccountID, FYear, FQuarter)
我得到的每一个结果$ 300 1季度或当我SUM OVER(PARTITION BY AccountID, FYear)
我总是得到$ 400每个记录。
我在百万以上的记录上这样做,所以我愿意接受建议。
请考虑向您的代码添加一些解释其他代码只有答案不够。 – Rahul