我已經試過所有我能得到的Current
列加起來。 '高爐','當前'和'未來'應該都等於零,我只需要一個快速檢查來驗證它。SQL Server:總結一列
代碼
SELECT
[AccountCode], [ExpensesCode], [CostCentre],
[NLYear], [NLPeriod],
SUM([BroughtForward]) AS 'BF',
SUM([CurrentPostings]) AS 'Current',
SUM([FuturePostings]) AS 'Future',
[Company]
FROM
[A_DW].[dbo].[NEW_ETL AccBalance]
WHERE
[Company] = 'GAR'
AND NLPeriod = '3' AND NLYear = '2017'
GROUP BY
[AccountCode], [ExpensesCode], [CostCentre], [NLYear], [NLPeriod], [Company]
這是自動線數據庫,並且數據是試用平衡,這樣看起來如下:
+-----+------+-----+------+---+---------+---------+------+
| 100 | 8000 | 700 | 2017 | 3 | 1000.00 | 2000.00 | 0.00 |
| 100 | 8001 | 700 | 2017 | 3 | 1500.00 | 4500.00 | 0.00 |
+-----+------+-----+------+---+---------+---------+------+
結果應該6500.00(2000.00 + 4500.00)
編輯你的問題,並提供樣品數據和預期結果。還要標記您正在使用的數據庫。你的查詢有什麼問題? –
這3列的色譜柱類型是什麼?在這一點上我真的沒有看到任何錯誤。 – Jens
這是非標準的SQL。你正在使用哪個DBMS? –