Skip to content
Advertisement

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.

Advertisement

Answer

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;
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement