以下视图应该计算Total 和 Amount 之间的差异。但是如果在 bill_pay_allocations 中没有输入相应的付款,则视图计算失败。即使没有相应的付款,我如何计算差额?
SELECT
`alphabase`.`bill_ing_sheets`.`INVOICE_NO` AS `INVOICE_NO`,
`alphabase`.`bill_ing_sheets`.`TOTAL` AS `TOTAL`,
`alphabase`.`bill_pay_allocations`.`AMOUNT` AS `AMOUNT`,
`alphabase`.`bill_pay_allocations`.`AMOUNT` - `alphabase`.`bill_ing_sheets`.`TOTAL` AS `Difference`
FROM
`alphabase`.`bill_ing_sheets` left join `alphabase`.`bill_pay_allocations`
ON
`alphabase`.`bill_pay_allocations`.`BILLING_ID` = `alphabase`.`bill_ing_sheets`.`BILLING_ID`
left join `alphabase`.`bill_payments`
ON
`alphabase`.`bill_payments`.`PAYMENT_ID` = `alphabase`.`bill_pay_allocations`.`PAYMENT_ID`