Showing COUNT greater than 10

  • 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

  • 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.

  • 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.

  • 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.

  • 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