<分区>
我被困了很长时间,无法找到我的查询有什么问题,我的 LEFT JOIN
中的 debit column
有问题,显示在Query Result image
如下所示。我的 debit table
的实际值是 500
但 MYSQL
查询显示为 1500
。
我在这里做错了什么。请帮助我。
这是我的客户表
这是我的cust_credit 表
这是我的cust_debit 表
MYSQL查询
如下
SELECT
customers.id as id,
customers.cust_name AS customer_name,
SUM(cust_debit.debit_amount) as debit,
SUM(cust_credit.credit_amount) as credit,
(SUM(cust_debit.debit_amount)) - (SUM(cust_credit.credit_amount)) as balance
FROM customers
LEFT JOIN cust_debit ON customers.id = cust_debit.cust_id
LEFT JOIN cust_credit ON customers.id = cust_credit.cust_id
GROUP BY customers.id
ORDER BY customers.id
我的查询结果
如下所示