sql与雇主表?薪水和advance_payment

时间:2013-05-17 15:54:34

标签: sql

如何获得此付款?

employer_payment.payment = employer_salary.salary - employer_advance_payment.advance_payment

enter image description here

请就如何解决此问题向我提出建议?

1 个答案:

答案 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