Advertisement
imk0tter

Untitled

Feb 14th, 2012
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 1.61 KB | None | 0 0
  1. SELECT
  2.         A.FirstName,
  3.         A.LastName,
  4.         A.EmployeeID,
  5.         B.PhonesPerDay AS PhonesToday
  6.         AVG(A.TimePerPhone),
  7.         AVG(A.PhonesPerDay)
  8. FROM
  9.         (SELECT
  10.                 A.FirstName,
  11.                 A.LastName,
  12.                 A.EmployeeID,
  13.                 AVG(B.Timer) AS TimePerPhone,
  14.                 COUNT(DISTINCT B.AuditID) AS PhonesPerDay,
  15.                 CONVERT(DATE, B.AuditDate) AS AuditDate
  16.         FROM
  17.                 EmployeeTable AS A,
  18.                 AuditTable AS B
  19.         WHERE
  20.                 A.EmployeeID = B.EmployeeID
  21.         GROUP BY
  22.                 A.FirstName,
  23.                 A.LastName,
  24.                 A.EmployeeID,
  25.                 AuditDate
  26.         ORDER BY
  27.                 AuditDate DESC
  28.         ) AS A,
  29.         (SELECT
  30.                 A.FirstName,
  31.                 A.LastName,
  32.                 A.EmployeeID,
  33.                 AVG(B.Timer) AS TimePerPhone,
  34.                 COUNT(DISTINCT B.AuditID) AS PhonesPerDay,
  35.                 CONVERT(DATE, B.AuditDate) AS AuditDate
  36.         FROM
  37.                 EmployeeTable AS A,
  38.                 AuditTable AS B
  39.         WHERE
  40.                 A.EmployeeID = B.EmployeeID
  41.                 AND
  42.                 AuditDate = GETDATE()
  43.         GROUP BY
  44.                 A.FirstName,
  45.                 A.LastName,
  46.                 A.EmployeeID,
  47.                 AuditDate
  48.         ORDER BY
  49.                 AuditDate DESC
  50.         ) AS B
  51. WHERE
  52.         A.EmployeeID = B.EmployeeID
  53. GROUP BY
  54.         A.FirstName,
  55.         A.LastName,
  56.         A.EmployeeID,
  57.         PhonesToday
  58. ORDER BY
  59.         PhonesToday DESC
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement