我在sql中写了以下视图
SELECT TOP (100) PERCENT Accounting.TopicA.CodeA, SUM(Accounting.DocumentDetail.Debit) AS DEB, SUM(Accounting.DocumentDetail.Credit) AS CRED,
Accounting.TopicA.Description
FROM Accounting.TopicA INNER JOIN
Accounting.DocumentDetail ON Accounting.TopicA.CodeA = SUBSTRING(Accounting.DocumentDetail.Topic, 1, 2)
GROUP BY Accounting.TopicA.CodeA, Accounting.TopicA.Description
ORDER BY Accounting.TopicA.CodeA
结果是
codea |Description | DEB | CRED |
1 Bank | 100 | 30 |
2 Cash | 40 | 70 |
.
.
.
现在我需要再添加两列来减去 DEB 和 CRED,比如当减法为正时,然后将结果放在 POS 列中,否则 NEG 列如下所示
codea |Description | DEB | CRED | NEG | POS |
1 Bank | 100 | 30 | 70 | 0 |
2 Cash | 40 | 70 | 0 | 30 |
.
.
.