此 select 语句返回每行的 timeid 的所有值。联接在正确的唯一值上联接。我已经尝试过内连接/左外/右外和完全也选择不同的无济于事。
SELECT
timed.timeid AS [Time Number],
emp.firstname AS [First Name],
emp.surname AS [Surame],
emp.empid AS [Employee Number],
timed.ver AS [Ver],
timed.tdate AS [Date],
shifts.code AS [Code],
timed.stime AS [Start],
timed.etime AS [End],
DATEDIFF(HOUR, timed.stime, timed.etime) AS [Hours]
FROM
emp
INNER JOIN timed ON emp.divid = timed.divid
INNER JOIN shifts ON timed.shiftid = shifts.shiftid
Time Number First Name Surame Employee Number Ver Date Code Start End Hours
OPS93041 C BLOGS G100 142 30/04/2013 Nts 19:00:00 06:00:00 11
OPS93041 L SMITH I101 142 30/04/2013 Nts 19:00:00 06:00:00 11
OPS93041 M WALKER M115 142 30/04/2013 Nts 19:00:00 06:00:00 11
OPS93041 P DJANGO P965 142 30/04/2013 Nts 19:00:00 06:00:00 11
正如上面结果的小例子所示,它正在将 timeid 添加到所有结果中,也可能是除了 emp 表中的值之外的其他值。
所需的输出将类似于。
Time Number First Name Surame Employee Number Ver Date Code Start End Hours
OPS93041 C BLOGS G100 142 30/04/2013 Nts 19:00:00 06:00:00 11
JDY73592 L SMITH I101 142 24/03/2013 Nts 11:00:00 17:00:00 6
QJA74057 M WALKER M115 188 08/07/2013 Nts 08:00:00 15:00:00 7
PDG03845 P DJANGO P965 125 19/01/2013 Nts 22:00:00 03:00:00 5