我有這個SQL查詢,我用它來查找每月每個帳戶的試算平衡移動。SQL - 返回累計每月列值
/* Fixed Assets 1 */
SELECT * FROM
(
SELECT T0.AcctCode AS 'SAP Code', T0.AcctName AS 'Description',
MONTH(T1.RefDate) AS Month, SUM(T1.Debit - T1.Credit) AS 'Amount'
FROM OACT T0
LEFT JOIN JDT1 T1 ON T0.[AcctCode] = T1.[Account]
WHERE T0.AcctCode LIKE '111%' AND T0.Levels = 5
AND (T1.RefDate BETWEEN DATEADD(yy, DATEDIFF(yy,0,{?AsAtDate}), 0) AND {?AsAtDate})
GROUP BY T0.AcctCode, T0.AcctName, T0.FatherNum, T1.RefDate) AS q
PIVOT
(
SUM(Amount)
FOR [Month] IN ([1],[2],[3],[4],[5],[6],[7],[8],[9],[10],[11],[12])
) AS query
這從六月返回以下結果:
我想包括這樣的所有行按月累積結果該行 1次的結果應該是:
1, 111110, Building Gross Value, 633604.23, 637764.23, 645313.03, 649061.78, 651097.78, 651097.78, 651397.78
我沒有成功實現這一目標。如何修改查詢來實現此目的?
其他數據:
查詢:
SELECT CAST(T0.TaxDate AS Date), T0.Account, T1.AcctName, T0.Debit, T0.Credit
FROM JDT1 T0 INNER JOIN OACT T1
ON T0.Account = T1.AcctCode
WHERE T0.[Account] = '111110'
返回:
提供一些測試數據 – TheGameiswar
我已經添加了一些信息 –