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,
- CONVERT(DATE, 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
- CONVERT(DATE, A.AuditDate) = 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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement