发薪日
id day employee income expenses tax
1 7 3 600 100 30
2 14 3 650 150 35
3 14 2 680 200 38
SELECT p.income, p.tax, ps.expenses
FROM paydays p
LEFT JOIN paydays ps ON ps.day+7 = p.day
WHERE p.day = 14 AND p.employee = 3
这给出了我想要的,第 14 天的 650 收入和 35 税,
以及第 7 天的 100 费用
现在的问题,
SELECT SUM(p.income), SUM(p.tax), SUM(ps.expenses)
FROM paydays p
LEFT JOIN paydays ps ON ps.day+7 = p.day
WHERE p.day = 14
它应该给
income = 1330
tax = 73
expenses = 100
但它将字段乘以 2,income = 2660, tax = 146.....