SHARE
TWEET

Advanced SQL, Problem 28

a guest Feb 14th, 2015 256 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. --Problem 28.  
  3. --Write a SQL query to display the number of managers from each town.
  4.  
  5. SELECT
  6.         Managers.TownName AS Town,
  7.         COUNT(Managers.managerId) AS [NUMBER OF managers]
  8. FROM (SELECT DISTINCT
  9.         e.EmployeeID AS managerId,
  10.         t.Name AS TownName
  11. FROM Employees e
  12. JOIN Employees m
  13.         ON e.EmployeeID = m.ManagerID
  14. JOIN Addresses a
  15.         ON a.AddressID = e.AddressID
  16. JOIN Towns t
  17.         ON t.TownID = a.TownID) AS Managers
  18. GROUP BY Managers.TownName
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top