Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SELECT
- A.FirstName,
- A.LastName,
- A.EmployeeID,
- A.JobName,
- COALESCE(C.PhonesToday, 0) AS PhonesToday,
- AVG(B.AvgTimePerPhone) AS AvgTimePerPhone,
- AVG(B.PhonesPerDay) AS AvgPhonesPerDay
- FROM
- (
- EmployeeTable AS A
- INNER JOIN
- (
- SELECT
- A.EmployeeID,
- B.JobName,
- B.JobID,
- AVG(A.Timer) AS AvgTimePerPhone,
- COUNT(DISTINCT A.JobEntryID) AS PhonesPerDay,
- DATEADD(dd,0, DATEDIFF(dd,0,A.AuditDate)) AS TechDate
- FROM
- JobEntryTable AS A
- INNER JOIN
- JobTable AS B
- ON A.JobID = B.JobID
- GROUP BY
- A.EmployeeID,
- TechDate,
- B.JobID,
- B.JobName
- ) AS B
- ON A.EmployeeID = B.EmployeeID
- )
- LEFT JOIN
- (
- SELECT
- A.EmployeeID,
- COUNT(A.JobEntryID) AS PhonesToday,
- A.JobID
- FROM
- JobEntryTable AS A
- WHERE
- DATEADD(dd,0, DATEDIFF(dd,0,A.TechDate)) = DATEADD(dd,0,DATEDIFF(dd,0,GETDATE()))
- GROUP BY
- A.EmployeeID,
- A.JobID
- ) AS C
- ON A.EmployeeID = C.EmployeeID AND B.JobID = C.JobID
- GROUP BY
- A.FirstName,
- A.LastName,
- A.EmployeeID,
- A.JobName,
- PhonesToday
- ORDER BY
- A.JobID DESC, PhonesToday DESC, AvgPhonesPerDay DESC
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement