如何获得此付款?
employer_payment.payment = employer_salary.salary - employer_advance_payment.advance_payment
请就如何解决此问题向我提出建议?
答案 0 :(得分:1)
您可以使用LEFT JOIN
来计算salary
扣除的advance_payment
。
SELECT a.employerID,
a.salary - COALESCE(b.advance_payment, 0) payment
FROM employer_salary a
LEFT JOIN employer_advance_payment b
ON a.employerID = b.employerID