SELECT clientid,SUM(balance) FROM
(SELECT clientid,cramount as balance FROM A
UNION ALL
SELECT clientid,- dramount as balance FROM B
)
GROUP BY clientid
SELECT (credit - debit) as balance
FROM (
(SELECT SUM(cr_amount) as credit,client_id FROM tbl_credit GROUP BY client_id) as credit
LEFT JOIN
(SELECT SUM(dr_amount) as debit,client_id FROM tbl_debit GROUP BY client_id) as debit
ON debit.client_id = credit.client_id)
union 可能效果最好,这是一个粗略的例子
我已经编辑了 sql ,请试试这个,让我知道谢谢。