I have 3 tables (attendance, allowances and deductions) with some records in attendance.Wage, allowances.Amount, deductions.Amount columns. And I want to "SUM" values in these columns with selected date.
Summed up values must be
- attendance.Wage:100
- allowances.Amount:150
- deductions.Amount:120
but with my query values are seeing very different.
SELECT Name, SUM(attendance.Wage), SUM(allowances.Amount), SUM(deductions.Amount) FROM employees
INNER JOIN attendance USING (EmployeeID)
INNER JOIN allowances USING (EmployeeID)
INNER JOIN deductions USING (EmployeeID)
WHERE MONTH(attendance.Date) = 6 AND YEAR(attendance.Date) = 2020
AND
MONTH(allowances.Date) = 6 AND YEAR(allowances.Date) = 2020
AND
MONTH(deductions.Date) = 6 AND YEAR(deductions.Date) = 2020
GROUP BY employees.EmployeeID;
Output of the query:
- attendance.Wage:400
- allowances.Amount:900
- deductions.Amount:720
Why the values are multiplying or increasing? How can I fix that?