Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- WITH
- DailyAuditStats AS
- (
- 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
- ),
- TodayAuditStats AS
- (
- SELECT
- A.EmployeeID,
- COUNT(A.AuditID) AS PhonesToday
- FROM
- AuditTable AS A
- WHERE
- CONVERT(DATE, A.AuditDate) = GETDATE()
- GROUP BY
- A.EmployeeID
- )
- 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
- DailyAuditStats AS B
- ON A.EmployeeID = B.EmployeeID
- )
- LEFT JOIN
- TodayAuditStats 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