0
我有三個表: 計費, debitcredit, JSO如何使一個聯盟而不是把底部它將把在左側MYSQL
我想總計計費按顧客分組,然後在左側添加總計debitcredit按顧客分組,然後在左側添加總計jso按顧客分組,我不能不要LEFT JOIN,因爲有些客戶在計費不debitcredit,在相同JSO
預期輸出:
subsid | debitamt | debitcredit | amount |
1 | 200 | null | 100 |
2 | null | 500 | 300 |
3 | 100 | 200 | 300 |
我嘗試這個查詢,但返回的斑點,我不知道它是否正確。
SELECT
IF(debitamt = "debitamt", 0, debitamt) as debitamt,
IF(debitcredit = "debitcredit", 0, debitcredit) as debitcredit,
IF(amount = "amount", 0, amount) as amount
from (
SELECT a.subsid, sum(debitamt) as debitamt, "debitcredit", "amount" FROM
new.billing a
UNION ALL
SELECT b.subsid, "debitamt", sum(debit-credit) as debitcredit, "amount"
FROM new.debitcredit b
UNION ALL
SELECT c.subsid, "debitamt", "debitcredit", sum(amount) as amount FROM
new.jso c
) a group by a.subsid
非常感謝你。
非常感謝你。它的工作:)。 –