Professional Documents
Culture Documents
Find the details of all the employees whose salary is greater than the salary of the senior most employee in the organization????.... Ans: select * from emp where sal>(select max(sal) from emp where hiredate=(select min(hiredate) from emp)); EMPNO ENAME O! M"# $%#E&A'E (A) ++++++ ++++++++++ +++++++++ ++++++++++ +++++++++ ++++++++++ ++++++++++ ++++++++++ ,-./ 0%N" P#E(%&EN' 1,+NO2+-1 3444 *OMM &EP'NO 14
2.Find the details of all the employees who are working in dept in which mosst of the employees are working? Ans: select * from emp where deptno=(select deptno from emp 5ro6p 78 deptno ha9in5 co6nt(*)>=(select max(co6nt(*)) from emp 5ro6p 78 deptno)); EMPNO ENAME O! M"# $%#E&A'E (A) +++++ ++++++++++ +++++++++ ++++++++++ +++++++++ ++++++++++ ++++++++++ ++++++++++ ,:// A))EN (A)E(MAN ,;/- <4+AP#+-1 1;44 ,3<1 =A#& (A)E(MAN ,;/- <<+>E!+-1 1<34 ,;3: MA#'%N (A)E(MAN ,;/- <-+(EP+-1 1<34 ,;/- !)A0E MANA"E# ,-./ 41+MA?+-1 <-34 ,-:: '@#NE# (A)E(MAN ,;/- 4-+(EP+-1 1344 ,/44 AME( *)E#0 ,;/- 4.+&E*+-1 /34 *OMM .44 344 1:44 4 &EP'NO .4 .4 .4 .4 .4 .4
3.Find the employee name sal grade dname of all the employees whose grade !s 3? Ans: select eAenameB eAsalB sA5radeB dAdname from emp eBdept dBsal5rade s where eAdeptno=dAdeptno and sA5rade=. and eAsal>(select losal from sal5rade where 5rade=.) and eAsalC=(select hisal from sal5rade where 5rade=.);
ENAME (A) "#A&E &NAME ++++++++++ ++++++++++ ++++++++++ ++++++++++++++ A))EN 1;44 . (A)E( '@#NE# 1344 . (A)E(
:A
Find the details of all the employees who are at the 2nd le"el in the organizationD Ans: select eAenameBeAsalBsA5radeBdAdname from emp eBdept dBsal5rade s where eAdeptno=dAdeptno and sA5rade=< and eAsal>sAlosal and eAsalC=sAhisal ENAME (A) "#A&E &NAME ++++++++++ ++++++++++ ++++++++++ ++++++++++++++
Find the details of the 3rd highest salary earning employee in the organization? Ans: select * from emp e where .=(select co6nt(distinct sal) from emp where sal>=eAsal);
EMPNO ENAME O! M"# $%#E&A'E (A) ++++++ ++++++++++ +++++++++ ++++++++++ +++++++++ ++++++++++ ++++++++++ ++++++++++ ,,-- (*O'' ANA)?(' ,3;; 4/+&E*+-< .444 ,/4< >O#& ANA)?(' ,3;; 4.+&E*+-1 .444 #.
*OMM
$isplay the details of all the employees who are ha"ing a salary greater than the highest salary earning person of the 3%th dept? Ans: select * from emp where sal>(select max(sal) from emp where deptno=.4);
EMPNO ENAME O! M"# $%#E&A'E (A) ++++++ ++++++++++ +++++++++ ++++++++++ +++++++++ ++++++++++ ++++++++++ ++++++++++ ,3;; ONE( MANA"E# ,-./ 4<+AP#+-1 </,3 ,,-- (*O'' ANA)?(' ,3;; 4/+&E*+-< .444 ,-./ 0%N" P#E(%&EN' 1,+NO2+-1 3444 ,/4< >O#& ANA)?(' ,3;; 4.+&E*+-1 .444 ,441 ford clerE ,3;; 1,+&E*+-4 :444 &.
*OMM
144
$isplay the details of all the employees who are working in the dept in which 'ost of the employees are working? Ans: select * from emp where deptno=(select deptno from emp where sal>(select losal from sal5rade where 5rade =.) and salC=(select hisal from sal5rade where 5rade=.) 5ro6p 78 deptno ha9in5 co6nt(*)>=(select max(co6nt(*)) from emp where sal>(select losal from sal5rade where 5rade=.) and salC=(select hisal from sal5rade where 5rade=.) 5ro6p 78 deptno));
EMPNO ENAME O! M"# $%#E&A'E (A) ++++++ ++++++++++ +++++++++ ++++++++++ +++++++++ ++++++++++ ++++++++++ ++++++++++ ,:// A))EN (A)E(MAN ,;/- <4+AP#+-1 1;44 ,3<1 =A#& (A)E(MAN ,;/- <<+>E!+-1 1<34 ,;3: MA#'%N (A)E(MAN ,;/- <-+(EP+-1 1<34 ,;/- !)A0E MANA"E# ,-./ 41+MA?+-1 <-34 ,-:: '@#NE# (A)E(MAN ,;/- 4-+(EP+-1 1344 ,/44 AME( *)E#0 ,;/- 4.+&E*+-1 /34
&EP'NO .4 .4 .4 .4 .4 .4
$isplay the details of all the employees who )oined in a year in which most of the employees )oined the organization? Ans: select * from emp where toFchar(hiredateBG8888G)= (select toFchar(hiredateBG8888G) from emp 5ro6p 78 toFchar(hiredateBG8888G) ha9in5 co6nt(*)>=(select max(co6nt(*)) from emp 5ro6p 78 toFchar(hiredateBG8888G))); EMPNO ENAME O! M"# $%#E&A'E (A) ++++++ ++++++++++ +++++++++ ++++++++++ +++++++++ ++++++++++ ++++++++++ ++++++++++ ,:// A))EN (A)E(MAN ,;/- <4+AP#+-1 1;44 ,3<1 =A#& (A)E(MAN ,;/- <<+>E!+-1 1<34 ,3;; ONE( MANA"E# ,-./ 4<+AP#+-1 </,3 ,;3: MA#'%N (A)E(MAN ,;/- <-+(EP+-1 1<34 ,;/- !)A0E MANA"E# ,-./ 41+MA?+-1 <-34 ,,-< *)A#0 MANA"E# ,-./ 4/+ @N+-1 <:34 ,-./ 0%N" P#E(%&EN' 1,+NO2+-1 3444 ,-:: '@#NE# (A)E(MAN ,;/- 4-+(EP+-1 1344 ,/44 AME( *)E#0 ,;/- 4.+&E*+-1 /34 ,/4< >O#& ANA)?(' ,3;; 4.+&E*+-1 .444 *OMM .44 344 1:44 &EP'NO .4 .4 <4 .4 .4 14 14 .4 .4 <4
(.
*.
$isplay the details of clerks who )oined in a year in which most of the employees )oined the organization? Ans: select * from emp where toFchar(hiredateBG8888G)= (select toFchar(hiredateBG8888G) from emp 5ro6p 78 toFchar(hiredateBG8888G) ha9in5 co6nt(*)>=(select max(co6nt(*)) from emp 5ro6p 78 toFchar(hiredateBG8888G))) and Ho7=G*)E#0G;
EMPNO ENAME O! M"# $%#E&A'E (A) ++++++ ++++++++++ +++++++++ ++++++++++ +++++++++ ++++++++++ ++++++++++ ++++++++++ ,/44 AME( *)E#0 ,;/- 4.+&E*+-1 /34
*OMM
&EP'NO .4
1%. $isplay the details of clerks who reporting to a employee who is the highest the 3rd le"el employee of the org? Ans: select * from emp where m5r=(select m5r from emp where sal=(select max(eAsal) from emp eBsal5rade s where sA5rade=. and eAsal>sAlosal and eAsalC=sAhisal)); EMPNO ENAME O! M"# $%#E&A'E (A) ++++++ ++++++++++ +++++++++ ++++++++++ +++++++++ ++++++++++ ++++++++++ ++++++++++ ,:// A))EN (A)E(MAN ,;/- <4+AP#+-1 1;44 ,3<1 =A#& (A)E(MAN ,;/- <<+>E!+-1 1<34 ,;3: MA#'%N (A)E(MAN ,;/- <-+(EP+-1 1<34 ,-:: '@#NE# (A)E(MAN ,;/- 4-+(EP+-1 1344 *OMM .44 344 1:44 4
&EP'NO .4 .4 .4 .4
,/44 AME(
*)E#0
,;/- 4.+&E*+-1
/34
.4