April 14, 2011 at 7:08 am
hi, i cant get this code to work..need to show the departments which have a count greater than 10...
select COUNT (employee_no) as 'Number of Employees in Section',Department_Name
from Employees
INNER JOIN
Departments
on Departments.Department_No=Employees.Department_No
having
COUNT(*) >10
group by department_name
April 14, 2011 at 7:11 am
What happens when you run it?
Dan
If only I could snap my figures and have all the correct indexes apear and the buffer clean and.... Start day dream here.
April 14, 2011 at 7:12 am
Column 'Departments.Department_Name' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
April 14, 2011 at 7:17 am
I think it might be getting confused try adding an alias for the tables like so.
select COUNT (empl.employee_no) as 'Number of Employees in Section',dep.Department_Name
from Employees empl
INNER JOIN
Departments dep
on dep.Department_No=empl.Department_No
having
COUNT(*) >10
group by dep.department_name
Dan
If only I could snap my figures and have all the correct indexes apear and the buffer clean and.... Start day dream here.
April 15, 2011 at 5:51 am
select COUNT (empl.EmpID) as 'Number of Employees in Section',dep.DepName
from Employee empl
INNER JOIN
Department dep
on dep.DepID=empl.DepID
group by dep.DepName
having
COUNT(*) >10
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply