Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
7. Display all the employee names in Research and Sales Department who are having
at least 1 person reporting to them
select empno, ename, job from emp where deptno in ( select deptno from dept where
dname in ('SALES','RESEARCH')) and
empno in (select mgr from emp);
select empno, ename, job,mgr from emp where empno in (select mgr from emp e group
by mgr
having count(*)>=2);
10. List the department names which are having more than 5 employees
select *from dept where deptno in (select deptno from emp group by deptno having
count(*)>5);
17. Write a query to get 2nd & 6th max salary from EMP table
21. List all the employees whose salaries are greater than their respective
departmental average salary.
select * from emp e where sal>(select avg(sal) from emp d where d.deptno=e.deptno);
*******or*********
select *from emp order by sal desc;
SELECT*
FROM emp e
WHERE e.sal > (SELECT AVG(e1.sal)
FROM emp e1
WHERE e1.deptno = e.deptno);
GROUP BY e.deptno;
12. List employees from research and accounting having at-least 2 reporting
select * from emp where deptno in (select deptno from dept where dname in
('RESEARCH','ACCOUNTING') and
empno in (select mgr from emp group by mgr having count(*)>=2 ));