如果有相同的组名称,我想减去Open Balance Cells,我的意思是Balance_type 0是借方,1是贷方 我期待结果是具有相同组名
的未结余额的借方贷方我的真实SQL语句就是这个:
SELECT
tblLedgerGroup.group_type, tblLedgerGroup.group_name, tblLedgerGroup_1.group_name AS [Group Name]
, SUM(tblLedgerNames.op_balance) AS [Open Balance]
, tblLedgerNames.balance_type
, SUM(tblCashLedger.debit) AS [Total Debit]
, SUM(tblCashLedger.credit) AS [Total Credit]
FROM
tblLedgerGroup
LEFT OUTER JOIN
tblLedgerGroup AS tblLedgerGroup_1 ON tblLedgerGroup.group_id = tblLedgerGroup_1.parent_group_id
LEFT OUTER JOIN
tblLedgerNames ON tblLedgerGroup_1.group_id = tblLedgerNames.group_id
LEFT OUTER JOIN
tblCashLedger ON tblLedgerNames.ledger_id = tblCashLedger.account_id
GROUP BY
tblLedgerGroup.group_type, tblLedgerGroup.group_name, tblLedgerGroup_1.group_name, tblLedgerNames.balance_type