我在gfee和netpay上得到錯誤的值。mysql上的錯誤值INNER JOIN
SELECT s.id, s.name, c.name AS course_name,
s.open_bal AS open_balance, sum(i.amount) AS gross_fee,
sum(i.discount) AS discount, sum(i.amount) - sum(i.discount) AS net_payable,
SUM(r.reg_fee+r.tut_fee+r.other_fee) AS net_recieved,
(sum(i.amount) - sum(i.discount)) - SUM(r.reg_fee+r.tut_fee+r.other_fee) AS balance_due
FROM subscribers s
INNER JOIN courses c on c.id = s.course_id
LEFT JOIN invoices i on i.student_id = s.id
LEFT JOIN recipts r on r.student_id = s.id
GROUP BY s.id;
這是怎麼發生的?
你對'錯誤'有什麼意思?你會得到什麼,你期望什麼是正確的? – 2011-04-13 13:32:34
@ypercube我得到了70000作爲gross_fee而不是35000 – seoppc 2011-04-13 13:33:59
聽起來就像你在'recipts'有兩條記錄'student_id'。也許你錯過了一些額外的連接條件? – 2011-04-13 13:37:32