Advertisement
Guest User

sql

a guest
Jul 2nd, 2015
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 0.36 KB | None | 0 0
  1. WITH Grouped (TownName, EmployeesCount)
  2. AS
  3. (
  4.     SELECT t.Name, COUNT(e.EmployeeID) AS EmployeesCount FROM Employees e
  5.         JOIN Addresses a ON e.AddressID = a.AddressID
  6.         JOIN Towns t ON a.TownID = t.TownID
  7.         GROUP BY t.Name
  8. )
  9.  
  10. SELECT TownName, EmployeesCount
  11. FROM Grouped g
  12. WHERE g.EmployeesCount =
  13.     (SELECT MAX(s.EmployeesCount) AS MaxCount
  14.     FROM Grouped s)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement