--highest sal
select ENAME,sal from emp where sal=(select max(sal) from emp)
2nd highest sal
select ename,sal from emp a where 2=(select count(distinct(sal)) from emp b where A.SAL<=B.SAL )
3rd highest sal
select ename,sal from emp a where 3=(select count(distinct(sal)) from emp b where A.SAL<=B.SAL )
1st highest sal in each department
select * from emp a where 1=(select count(distinct(sal))from emp b where A.DEPTNO=B.DEPTNO and A.SAL<=B.SAL )
highest sal in specific department
select * from emp a where 1=(select count(distinct(sal))from emp b where A.DEPTNO=B.DEPTNO and A.SAL<=B.SAL and a.deptn0=20 )
select ENAME,sal from emp where sal=(select max(sal) from emp)
2nd highest sal
select ename,sal from emp a where 2=(select count(distinct(sal)) from emp b where A.SAL<=B.SAL )
3rd highest sal
select ename,sal from emp a where 3=(select count(distinct(sal)) from emp b where A.SAL<=B.SAL )
1st highest sal in each department
select * from emp a where 1=(select count(distinct(sal))from emp b where A.DEPTNO=B.DEPTNO and A.SAL<=B.SAL )
highest sal in specific department
select * from emp a where 1=(select count(distinct(sal))from emp b where A.DEPTNO=B.DEPTNO and A.SAL<=B.SAL and a.deptn0=20 )
No comments:
Post a Comment