Oracle Database Query to be solved

create table employee
    (emp_id     integer     not null,
     manager_id     integer     not null,   
     emp_name   char(20)    not null,
     emp_tel    char(10),
     emp_salary number      not null,
     hire_date  date,
    constraint pk_employee primary key(emp_id)
    );

alter table employee 
add constraint fk_employee_manager foreign key(manager_id) 
references employee(emp_id);

Need help to Find the ID of managers that have more than 5 employees working with them.

Upvotes: 0

Views: 58

Answers (2)

rsreji
rsreji

Reputation: 180

insert into employee (emp_id, manager_id, emp_name, emp_salary)
select 1, 1, 'A', 1000 from dual
union select 2, 1, 'A', 1000 from dual
union select 3, 1, 'A', 1000 from dual
union select 4, 1, 'A', 1000 from dual
union select 5, 1, 'A', 1000 from dual
union select 6, 1, 'A', 1000 from dual
union select 7, 2, 'A', 1000 from dual;

select manager_id, count(emp_id) from employee group by manager_id
having count(emp_id) > 5;

Upvotes: 0

zip
zip

Reputation: 4061

just do this: You need to familialrize yourself with the possibilities of grouping functions

select manager_id     
from employee
group by manager_id     
having count(*)>5

Upvotes: 1

Related Questions