选择所有雇员后,此查询将不会仅返回每个雇员的计算。我只尝试返回“ Clock-In”和“ Clock-Out”之间的时间的结果。任何帮助将不胜感激!
SELECT DISTINCT i.SerialNumber, it.Name AS EmployeeName, cs.Value AS
StepValue, cs.ModifiedOnUtc AS TimeStamp, CASE WHEN cs.Value = 'Clocked-In'
THEN NULL WHEN cs.Value <> 'Clocked-In' THEN (CASE WHEN LAG(cs.Value, 1, 0)
OVER (ORDER BY it.Name, cs.modifiedonserverutc)
<> 'Clocked-In' THEN NULL WHEN LAG(cs.Value, 1, 0) OVER (ORDER BY it.name,
cs.ModifiedOnUtc) = 'Clocked-in' THEN DATEDIFF(minute, LAG(cs.ModifiedOnUtc,
1, 0) OVER (ORDER BY it.name, cs.ModifiedOnUtc), cs.ModifiedOnUtc) ELSE NULL
END) END AS MinutesWorked