2010-09-13 17:40:27 UTC
department:
CREATE TABLE department
( DEPARTMENT_ID NUMBER(4) PRIMARY KEY,
DEPARTMENT_NAME VARCHAR2(20),
ADDRESS VARCHAR2(20));
and employee:
CREATE TABLE employee
( EMPLOYEE_ID NUMBER(4) PRIMARY KEY,
EMPLOYEE_NAME VARCHAR2(20),
JOB VARCHAR2(20),
MANAGER_ID NUMBER(4),
HIRE_DATE DATE,
SALARY NUMBER(9, 2),
COMMISSION NUMBER(9, 2),
DEPARTMENT_ID NUMBER(4) REFERENCES department(DEPARTMENT_ID));
I am trying to count how many employees each department has and display only the highest result. I've gotten to this point:
select d1.department_name, count(t1.department_id) as number_of_employees
from employee t1, department d1
where t1.department_id(+) = d1.department_id group by d1.department_name, d1.address
order by d1.department_name
this gives me the results I need to know by displaying the department names and how many employees work for each, but how would I go about only displaying the department with the highest number of employees. Using the MAX function was suggested to me, but I don't think you can use it on the count function since it isn't a permanent attribute of the department table. Any help is greatly appreciated.