请教大家一个关于多表连接的问题:
在ACCESS数据库里共有四个表: Employee记录员工信息, Attendance记录考勤, Output记录产量, Rejection记录返工次数。
我的意图是在一个查询表里加总统计出某一时间段的各项情况,包括考勤,产量及返工次数等。 我的SQL语句如下,但出来的结果完全不对,好像累加了几次后的结果。 本人对SQL只有一些表面粗略的了解,麻烦大家帮忙看一下。谢谢。
SELECT e.EmployeeID AS 工號,
e.ChineseName AS 姓名, e.EnglishName AS 英文名, sum(a.OvertimeDuration) AS 加班, sum(a.LeaveDuration) AS 请假, sum(o.OutputA) AS 产量A, sum(o.OutputB) AS 产量B, sum(o.OutputC) AS 产量C, sum(r.Quantity) AS 返工次数
FROM ((Employee e INNER JOIN Attendance a ON e.EmployeeID = a.EmployeeNo) INNER JOIN Output o ON e.System = o.SystemID) INNER JOIN Rejection r ON e.System = r.System
WHERE a.ApplyDate BETWEEN '2012-01-01' AND '2012-12-31' AND o.WorkDate BETWEEN '2012-01-01' AND '2012-12-31' AND r.SubmmitDate BETWEEN '2012-01-01' AND '2012-12-31'
GROUP BY e.EmployeeID, e.ChineseName, e.EnglishName
|