Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SELECT
- A.FirstName,
- A.LastName,
- A.EmployeeID,
- 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,
- AVG(A.Timer) AS AvgTimePerPhone,
- COUNT(DISTINCT A.AuditID) AS PhonesPerDay,
- DATEADD(dd,0, DATEDIFF(dd,0,A.AuditDate)) AS AuditDate
- FROM
- AuditTable AS A
- GROUP BY
- A.EmployeeID,
- AuditDate
- ) AS B
- ON A.EmployeeID = B.EmployeeID
- )
- LEFT JOIN
- (
- SELECT
- A.EmployeeID,
- COUNT(A.AuditID) AS PhonesToday
- FROM
- AuditTable AS A
- WHERE
- DATEADD(dd,0, DATEDIFF(dd,0,A.AuditDate)) = DATEADD(dd,0,DATEDIFF(dd,0,GETDATE()))
- GROUP BY
- A.EmployeeID
- ) AS C
- ON A.EmployeeID = C.EmployeeID
- GROUP BY
- A.FirstName,
- A.LastName,
- A.EmployeeID,
- PhonesToday
- ORDER BY
- PhonesToday DESC, AvgPhonesPerDay DESC
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement