1

I'm supposed to display the name of the department in which there are at least four employees. I tried a few different methods, including this one:

SELECT Department, COUNT(EmployeeID) AS NumberOfEmployee
FROM Deparment d INNER JOIN Employees e
ON d.DeparmentID = e.DeparmentID
GROUP BY Deparment
HAVING NumberOfEmployee >= 4;

When I run the query, it is asking me to enter the parameter value for NumberOfEmployee. Can anyone tell me what's wrong?

Chris Mukherjee
  • 841
  • 9
  • 25
Mplus
  • 79
  • 7

1 Answers1

2

Try this instead:

SELECT Department, COUNT(EmployeeID) AS NumberOfEmployee
FROM Deparment d INNER JOIN Employees e
ON d.DeparmentID = e.DeparmentID
GROUP BY Deparment
HAVING COUNT(EmployeeID) >= 4;

Your original HAVING clause was invalid (you cannot use an alias in it).

László Koller
  • 1,139
  • 6
  • 15
  • @Mplus: On StackExchange sites, like StackOverflow (aka. SO), it's considered proper etiquette to mark the correct answer as the 'accepted answer'. Both to show all other SO readers that your question has been answered as well as to give the individual who spent time to answer your question credit for taking the time to do so. Welcome to StackOverflow! – László Koller Jun 16 '14 at 15:59