0% found this document useful (0 votes)
85 views29 pages

SQL Question For Employees Table

..

Uploaded by

Prabhu Gowda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
85 views29 pages

SQL Question For Employees Table

..

Uploaded by

Prabhu Gowda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 29
Emp tabledata TEMPNO | ENAME 108. ‘OMM_| DEPTNO. 7360. | SMITH CLERK 2 7499 | ALLEN ‘SALESMAN 00 2) 7521 | WARD ‘SALESMAN, 00 » 7266 | JONES MANAGER 2] 7654 | MARTIN SALESMAN 7698. 2e-Seps1| 1250 | 1400 x 7698 | BLAKE MANAGER. 7830, ‘01-May-81 | 2650 x 7782 | CLARK. MANAGER 7839 ‘08-Jun-81 | 2450 10 Tres | SCOTT ‘ANALYST 7556. '09-Decs2 | 3000 2 7830 | KING PRESIDENT 17-Nov81 | 5600 0 7e44 | TURNER | SALESMAN 7608, ‘Os-Sep-81| 1500 a = 7276 | ADAMS CLERK 77a 32Jan-83 | 1100 2] 7900. | JAMES CLERK 7098 O3-Decs1| 950 x 7802 | FORD ‘ANALYST 7566, 03-Decsi| 3000 2) 7534 | MILLER, CLERK Taz 23van-82 | 1300 0 ‘Dspttabledata DEPTNO | DNANE Loc 10 | ACCOUNTING NEW YORK 20 | RESEARCH DALLAS 30] SALES CHIGAGG 40 | OPERATIONS BOSTON 1. Display all the information of the EMP table? A) select * from emp; 2. Display unique Jobs from EMP table? A) select distinct job from emp; B) sclect unique job from emp; 3. List the emps in the ase order of their Salaries? A) select * from emp order by sal ase; 4. List the details of the emps in asc order of the Dptnas and dese of Jabs? A)sclect * from emp order by depino ase,job dese; $. Display all the unique job groups in the descending order? A)select distinet job from emp order by job dese; 1D) select * from emp where deptno not like “20°; 30, List all the emps except PRESIDENT’ & MGR" in ase order of Salaries, A) Select * from emp — where job not in (PRESIDENT ."MANAGER’) order by sal asc; By select * from emp where job not like 'PRESIDENT” and job not like*MANAGER’ order by sal_ asc; ©) Select * fiom emp where job != ‘PRESIDENT’ and job > ‘MANAGER* ‘order by sal asc; 31. List all the emps who joined before or after 1981. A) select * from cmp where io_char (hiredate,"VYYY") not in C1981") (OR) B) select * from emp where to_char ( hiredateYYYY") != “1981'; (OR) c) select * from emp where to_char(hiredate,"YYYY") <> ‘1981" ; (OR) D) select * from emp where to_char (hiredate ,"YYYY") not like ‘198 1"; 22, List the emps whose Empno not starting with digit78, A) select * from emp where empno not like “78% 33, List the emps who are working under * MGR’. A) select cename ||‘ works for ‘|| mename from emp ¢ emp m where ¢.mgr = mempno; — (OR) B) select ¢.ename || * has an employee ‘|| mename from emp @ , emp m where e.empno= mmgr; M4, List the emps who joined in any year but not belongs to the month of March. A) select * from emp where to_char (hiredate,"MON') not in (MAR’Y, (OR) B) select * from emp where to_char (hiredate,'MON') != ‘MAR’; (OR) oC select * from emp where to_charhiredate,’ MONTH") not like “MARY ; (OR) D) seleet * from emp where to_char{hiredste," MON") <> "MAR"; 35. List ll the Clerks of Deptno 20. “A)select * from emp where job ="CLERK:’ and deptno = 20; 36, List the emps of Deptno 30.or 10 joined inthe year 1981. ‘A) select * from emp where to_char(hiredate,"YYYY") = *1981* and (deptno =30 ‘or depino =10) ; (OR) select * from emp where to_ char (hiredate,"VYYY") in C1981") and (depino= 30 or deptno =10 ) ; 37. Display the details of SMITH. ‘A)select * from emp where ename = *SMITH" ; 38. Display the location of SMITH. A) select loc from emp 2, dept dwhere e.ename = ‘SMITH’ and_e.deptno = d.depino ; 39, List the total information of EMP ta -emps Working Under “AC COUNTING’ slong with DNAME and Loe of all the & ‘RESEARCH in the ase Deptno. Ay select * from emp e ,deptd where (dname = *ACCOUNTING’ or same “RESEARCH! Noted = eno order by eden (OR) B) select dept do where ddname in (ACCOUNTING RESEARCH "and c.deptno ~ dl depin order by e-depine ase, 40,List the Empno, Ename, Sal, Dname of all the ‘MGRS" and ‘ANALYST’ ‘working in New York, Dallas with an exp more than 7 years without receiving the ‘Comm asc order of Loc. A) select eempno.cename.esal,ddname from emp e dept d where doc in (‘NEW YORK",'DALLAS') and edeptno = d.deptno and e.empno in (select e.empno from emp e where ejob in (MANAGER',"ANALYST*) and (months _between(sysdate2 hiredatey 12)>7 and e.comm. is null) order by dhlos ase; 41, Display the Empno, Ename, Sal, Dname, Loc, Deptno, Job of all emps working at ‘CJICAGO or working for ACCOUNTING dept with Ann Sal>28000, but the Sal should not be=3000 or 2800 who doesn’t belongs to the Mgr and whose no is having a digit 7’ or “8 in 3“ position in the asc order of Deptno and desc order of job. ‘A) select E.ermpno,E.ename E.sal,D, dname,D loc, E.deptno, job from emp E,dept D where (Doc = ‘CHICAGO! or D.dname = ‘ACCOUNTING and Exleptno-D.depino and E.empno in (select E.empno from emp E where (12*Esal) > 28000 and E.sal not in (3000 2800) and E.job MANAGER’ and (E.empno like’ 7% or E.empno like *_ 8%) order by Edepino ase , Ejob des; 42. Display the total information of the emps along with Grades in the ase order. A) select * from emp ¢ .salgrade s where e.sal between s.losal and shisal_ order by grade ase; (OR) By) select * from emp ¢ ,salgrade s where ¢sal >= siosal and esal <= sisal orderby sgrade asc; (using between and is a bit simple) 43, List alll the Grade2 and Grade 3 emps, |A) select * from emp e where e.empno in (select e.empno from emp € salgrade s where ¢.sal between slosal and s,hisal and s grade in(2.3)), (OR) B) select * from emp e .salgrade s where e.sal between s.losal and s.hisal and sigrade in (23); 44, Display all Grade 4,5 Analyst and Mar. A) select * from emp e, silgrade s where esal between sJosal and s.hisal and sgride in (4,5) and cempno in (select c.empno from emp ¢ where ejob in (MANAGER", ANALYST") ): AS, List the Empno, Ename, Sal, Dmame, Grade, Exp, and Ann Sal of emps working for Dept! or20, A) selectE.empno.E ename,F sal. grade, Didname, (nonths_betweon(sysdate E.hiredate)/12) “EXP* ,12*Esal “ANN SAL” from emp E,dept D salgrade § where Edgpino in (10.20) and deine = Dadeptno and Esal between Sos and S.hisal; 46, Lis all the information of emp with Loc and the Grade of all the emps belong to the Grade range from 2 to 4 working at the Dept thase are not starting with char set ‘OP and not ending with ‘S’ with the designation having a char ‘a’ any where joined in the year 1981 but not in the month of Mar or Sep and Sal not end with “00° in the ase order of Grades A) select c.empno.cename,d.loc.s.grade,esal from emp e dept dsalgrade s where e.deptno = d.depino and (d.dname not like ‘OP! and d.dname not like '8(S') and e-sal between s lasal and s.hisal ands grade in (2.3.4) and empno in (select empno from emp where job like "%AY%'and sal not like "9600" and (to_char (hiredate"YYY¥") ="1981" and to_char(hiredate, MON’) not in (‘MAR'/SEP*)}; 47. List the details of the Depts along with Empno, Ename or without the emps A) select * from emp e,dept d where e.deptno('+)= d.deptno; 48. List the details of the emps whose Salaries more than the employee BLAKE. ‘A) select * fram emp where sal > (select sal from emp where cname = *BLAKE’); 49. List the emps whose Jobs are same as ALLEN, A) selzet * from emp where job = (select job from emp where ename = *ALLEN’), ‘50, List the emps who are senior to King A) select * from emp where hiredate < ( select hiredate from emp where ename=*KING'}; $1. List the Emps who are senior to their own MGRS. A) select * from cmp wemp m where wimgr = mempno and w-hiredate < mhiredate ; (OR) B) select * from emp w.emp m where w.empao= mamgr and whiredate> mhiredate; 52. Liat the Emps of Deptno 20 whose Jobs are same as Deptnol0. ‘A)select * from emp e dept d where d.depino ~20 and e.depino = ddepino and job in ( select ejob from emp e.dept di where e.depino = d.deptno and d.depino =10), 53, List the Emps whose Sal is same as FORD or SMITH in desc order of Sal. A) Select © from emp where sal in (select sal from emp where ( ename= ‘SMITH" ‘or ename = “FORD! )) order by sal dese: $4, List the emps Whose Jobs are same as MILLER or Sal is more than ALLEN ‘A) select " fom emp where job = (select job from emp where ename = *MILLER’ ) or sal>(select sal from emp where ename = “ALLEN’), $5, List the Emps whose Sal is > the total remuneration of the SALESMAN, A) select * from emp where sal >(select sum(avi2(commsal+comm.sal)) from emp where job="SALESMAN’); 56, List the emps who ate senior lo BLAKE working at CHICAGO & BOSTON. A) select * from emp e dept d where dloc in ((CHICAGO",,BOSTON’) and edeptno = ddeptno and chiredate <(select chiredate from cmp © where e.cname = “BLAKE’); 57. List the Emps of Grade 3.4 belongs to the dept ACCOUNTING and RESEARCH whose Sal is more than ALLEN and exp more than SMITH in the asc order of EXP. A) select * from emp © where edeptno in (select didepino from dept d where d.dname in (‘ACCOUNTING’,'RESEARCH') ) and e.sal >(select sal from emp where ename = “ALLEN ') and ehiredate <( select hiredate from emp where ename = ‘SMITH") and e.empno in (select cempno fom emp ¢ salgrade s where e.sal ‘between s.Josal and s.hisal and s.grade in (3,4) ) order by e hiredate dese; $8, List the emps whose jobs same as SMITH or ALLEN A) select * from amp where job in (select job from emp where name = *SMITH' or ename= “ALLEN*), (OR) B) select * from emp where job in (select job from emp where enam: in (SMITH"* ALLEN"), 59, Write a Query to display the details of emps whose Sal is same as of a) Employee Sal of EMP1 table, b) %4Sal of any Mgr of EMP2 table. s) The sal of any person with exp of $ years belongs to the sales dept of cemp3 table. d) Any grade 2 employee of emp4 table. €) Any grade 2 and 3 employee working fro sales dept or operations dept joined in 89, 60, Any jobs of depino 10 those that are not found in depino 20, A) select ejob from emp e where e.depino— 10 and e,job not in (select job from emp where deptno =20); 61, Lis of emps of emp! who are not found in emp2, 62. Find the highest sal of EMP table. A) select max(sal) from emp; 63. Find details of highest paid employee. AA) select * fhom emp where sal in (select max(sal) from emp); 4, Find the highest paid employee of sales department. A) select * from emp where sal in (select max(sal) from emp where depino in (select d.deptno from dept d where d.dname ="SALES')), 65, List the most recently hired emp of grade3 belongs to location CHICAGO, A) select * from emp ¢ where edeptno in ( select d.deptno from dept d where d.loc = CHICAGO) and e.hiredate in (select max(hiredate) from emp where empno in (select empno from emp e,salgrade s where e.sal between s losal and s hisal and s.grade= 3)) ; (or) select * from emp ¢,dept d where d.loc='chicago" and hiredate in(select max(hiredate) from emp ¢,silgrade s where sal between losal and hisal and grade=3); 66, List the employees who are senior to most recently hired employee working under king. A) select * fromemp where hiredate < (select max(hiredate) from emp where mgr in (select empno from emp where ename = 'KING')) ; 67. List the details of the employee belongs to newyork with grade 3 to 5 except ‘PRESIDENT’ whose sal> the highest paid employee of Chicago in a group where there is manager and salesman not working under king A) select * from emp where deptno in (select depino from dept where dept.loc ="NEW YORK’) and empno in (select empno from emp esalgrade s where ¢.sal between s.losal and s.hisal and s.grade in (3.4.5) ) and job != ‘PRESIDENT’ and sal >(select max(sal) from emp where deptno in (select deptno from dept where dept.loe = ‘CHICAGO) and job in (‘MANAGER''SALESMAN)) and mgr not in (select empno from emp where ename ="KING’));, 68. List the details of the senior employee belongs to 1981. A) select * from emp where hiredate in (select min(hiredate) from emp where to_char( hiredate,"YYYY") =*1981"); (OR) B) select * from emp where hiredate = (select min{hiredate) from emp where to_charthiredate,"YYYY") = 1981"); 69, List the employees who joined in 1981 with the job same as the most senior person of the year 1981. A)select * from emp where job in (select job from emp where hiredate in (select min(hiredate) from emp where to_char(hiredate,’YYYY") —'1981")); 70, List the most senior emp! working under the king and grade is more than 3. A) select * from emp where hiredste in (select min(hiredate) from emp where -empno in (sclect empne from emp ¢ .salgrade s where ¢.sal between s.losal and sisal and s.grade in (4.5))) and mgr in (Select empno from emp where ename= "KING; 71. Find the total sal given to the MGR. A) select sum(sal) from emp where job = MANAGER’; (OR) B) select sum(sal) from emp where empno in select mgr from emp); 72. Find the total annual sal to distribute job wise in the year 81 ‘A) select job,surn(12*sal) from emp where to_char(hiredate’¥ YYY") =*1981" group by job : 73. Display total sal emplayee belonging to grade 3. A) select sum(sal) from emp where empno in (select empno from emp e .salgrade s where ¢.sal between slosal and shisal and s.grade~ 3) 74, Display the average salaries of all the clerks. ‘A) select avg( al) from emp where job = *CLERK"; 75. List the employeein dept 20 whose sal is >the average sal Of dept 10 emp A) select * from emp where depo =20 and sal >(select avg (sal) from emp where deptna= 10); 76. Display the number of employee for each job group depino wise. A) select deptno job count(*) from emp group by depino,job: (or) B) select ddeptno.ejobcount(e.job) from emp edept d where esdepino(+)-ddeptne group by ejobd.depino; 77. List the manage mo and the number of employees working for those mgrs in the ascending Mgmo. A) select w.mgr ,count(*) from emp w,emp m where w.mngr= m.empno pi group by w.ngr order by wmgr ase; 78, List the department,details where at least two emps are working, A) select deptno ,count(*) from emp group by deptno having count(*) >= 2; 79, Display the Grade, Number of emps, and max sal of each grade. A) select s.grade ,count(*),max(sal) from emp e.salgrade s where sal between slosal and s.hisal ‘group by s.grade, 80, Display dname, grade, No, of emps where at least two emps are clerks. A) seloct d.dname,s.erade,count(*) from emp e,dept d,salgrade s where e.deptno = didepino and ejob = ‘CLERK’ and ¢.sal between s,losit and shisal_ group by ddname,s grade having count(*) >= 2; 81, List thedetails of the department where maximum number of emps are working, |A) select * from dept where deptno in (select depino from emp group by depino having count(*) in (select max(count(*)) from emp group by deptna) ); (OR) B) select d.depinod.dname,d.loc,counit*) from emp e dept d where e.depino = d.deptno group by ddeptnod.dname.d. loc having count(*) = (select max{count(*) ) fromemp group by deptno); 82, Display the emps whose manager name is jones. A) select ® from emp where mgr in (select empno from emp where ename=“JONES'); (OR) B) select * from emp where mgr = (select empno from emp where ename = “JONES'); 33. List the employees whose salary is more than 3000 after giving 20% increment. A) SELECT * FROM EMP WHERE (1.2"SAL)> 3000; 34, List the emps with dept names. A) select e.empno,e.ename,e job.e. mgr. hiredatee sal.e.comm,e.deptnod.dname from emp dept d where e.deptna = ddeptno; 85, List the emps who are not working in sales dept A) select * from emp where deptno mot in (select deptno from emp where dname = * SALES"); 86, List the emps name dept, sal and comm, For those whose salary is between 2000 and 5000 while loc is Chicago. A) select eename,e.deptno,¢.sale,comm from emp e¢ dept d where e.deptno = dideptno and d.loc= ‘CHICAGO’ and e.sal between 2000 and 5000; 87, List the emps whose sal is greater than his managers salary A) select * from emp w,emp m where w.mgr = mempno and w,sal > m,sal; 88, List the grade, EMP name for the deptno 10 or deptno 30 but sal grade is not 4 While they joined the company before "31 -ee-82, A) select s grade ,e.ename from emp e,salgrades where e.deptno in (10,20) and hiredate < (31 -DEC-82') and (e.sal between s.losal and s\hisal and s grade not in (a): 89, List the name job, dname, location for those who are working as MGRS, A) select ¢.ename,ejob,d.dname.d.loc from emp e dept d where e.deptno = d.deptno and eempno in (select mgr from emp ); 90. List the emps whose mgr name is jones and also list their manager name. A) select w.empno,w,ename,w.job,w.mgr, w.hiredate,w.sal,w.deptno,mename from emp w emp m where w.mgr = mempno and m.ename = JONES’; 91, List the name and salary of ford if his salary is equal to hisal of his grade, A) select e.ename,e.sal from emp e ,salgrade s where e.ename = "RORD' and e.sal between s.losal and s.hisal and ¢.sal = s.hisal ; 92. Litthe name, job, dname ,sal, grade dept wise A) select e.cname,e,job,d.dname,e.sal,s.grade from emp e,dept dsalgrade s where e.deptno = d.deptno and ¢.sal between s,losal and s.hisal order by ¢.deptno ; 93. List the emp name, job, sal, grade and dname except clerks and sort on the basis of highest sal. A) select ¢ename,e,job,e.sals.graded.dname from emp e dept d salgrade s where e.deptno = d.deptno and e.sal between slosal and s.hisal and «job not in(‘(CLERK’) order by e.sal dese; 94, List the emps name, job who are with out manager A) select e.ename;e.job from emp ¢ where mgr is null; 95. List thenames of the amps who are getting the highest sal dept wise. AA) select e.ename,edepino from emp where e sal in (select max(sal) from emp group by deptno) ; 9%, List the emps whose sal is equal to the average of max and minimum A)select * from emp where sal =(select (max(sal}+min(sal))2 fromemp); 97. Lis the no, of emps in each department where the no. is more than 3. A) select depino,couni(*) from emp group by depino having couni(*)< 3; 98, List the names of depts. Where atleast 3 are working in that department. A) select ddname,count(*) from emp ¢ dept d where edeptno = didepine group by ddname having count(*) >=3 ; 99, List the managers whose sil is more than his employess avg salary, AA) select * from emp m where mempno in (select mgr from emp) and msal > (select avgi c.sal) from emp ¢ where e.mgr ~m,empno ) The subquery does the samess @elect (awp(e.cal)),m.cname trom Sp, m.oname)g 100, List the name,silary.comm, For those employes whose net pay is greater than ‘or equal toany other emplayce salary of the company. A) select eenameesalecomm fm emp e where nvi2{¢.comm..¢.sab+e comm, ¢.sal) >=any (select sal from emp}; (OR) By select cname,sal.comm. from emp where saltnvicomm.0) >= ny (select sal from emp} 101, List the emp whose sal Asal; (OR) B) select * from emp wemp m where w.mgr= m.empno and w.sal any (select sal from emp where empno in (select mgr from emp)); 102. List the employee names and his average salary department wise. A) select ddepino, round(avg(nvi2(el.comm, el saltel.comm, el-sal))) avg. 2.cname from emp el, emp ¢2, dept d where d.depino =el.depino and ddeptno = e2.deptno group by d.deptno, 22. ename; (or) B) select d.maxsal,e.ename,e.deptno as “current sal” from emp e, (select avg(Sal) maxsal,depmno from emp group by depto) d where e.deptno=d.depino; 103. Find out least S$ eamers of the company. ‘A) select * from emp e where $> (select count(*) from emp where sal >sal); (or) B) select rownum rank,empno,ename,job,sal from (select * from emp order by sal asc) where rownum < 6; (or) C) select * from emp ¢ where 5 >(select count(distinct sal) from emp where e sal > sal); 104. Find out emps whose salaries greater than salaries of their managers. A) select * from emp w.emp m where w.mgr = mempno and w.sal> msal; (OR) B) select * from emp ¢ (select * from emp where empno in (select mgr from emp)) a where e-sal >a.sal and e.mgr=a.empno 105. List the managers who are not working under the president. A) select * from emp where empno in{select mgr from emp) and mgr not in (select empno from emp where job = PRESIDENT) 106. List the records from emp whose deptno isnot in dept. 107. Listthe Name , Salary, Comm and Net Pay is more than any other employee. A) Select eename.e.sal,¢ comm,nvl2(comm,sal+comm,sal) NETPAY from emp e where nvl2(commsal+comm,sal) > any (select sal from emp where empno =e.empno) ; 108, Listthe Enames who are retiting after 31-Dec-89 the max Job petiod is 20Y. A) select ename from emp where add_months(hiredate.240) > '31-DEC-89°, B) select ename from emp where add_months(hiredate,240) > to_date(’31-DEC-89" ,"DD-MON-RR’), 109, List those Emps whose Salary is odd value, A)select * from emp where mod(sal,2) = 1; 110, Listthe emp's whose Salary contain 3 digits, ‘A)select * from emp where length (sal) = 3; 111, Listthe emps who joined én the month of DEC. A) select * from emp where to charfhiredate,"MON’) ="DEC’; (Ry B) select * from emp where to_char(hiredate,’MON") in (‘DEC’); (OR) C) select * from emp where to_char{hiredate," MONTH’) like "DEC 112, Listthe emps whose names contains “A* ‘A)select * from emp where ename like “%4A° 113, List the emps whose Depino is available in his Salary, A) select * from emp where instr(sal,deptno) > 0; 114, Listthe emps whase first 2 chars from Hiredate=last 2 characters of Salary, A) select * fromemp where substi(hiredate, 12) = substr(sal length(sal)-I,length(sal)); 115, List the emps Whose 10% of Salary is equal to year of joining, A) select * from emp where to_char(hiredate, YY") in (select. 1*sal from emp); 116, List first $0% of chars of Ename in Lower Case and remaining are upper Case A) select lower substr(ename, | round(length(ename)/2))) |[substr(ename,round length{ename)/2}+|,Jen gth{ename)) from emp ; (OR) B) select lower{ substr(ename, 1 ,ciel(length(ename)/2))) ||Substy ename,eielength ename)/2)+ I,length(ename)) from emp ; 117, Listthe Dname whose No, of Emps is =to number of chars in the Dname. 16 A) select * from dept d where length(dname) in (select count(*) from emp e where e.deptno = ddepino ); (or) B) select ddname.count(*) from emp e dept d where edeptno dldeptno. group by dhame having courne)~ eng (dna); 118, List the emps those who joined in company before 15* of the month. A) select * from emp where to_char(hiredate,’DD') <"15'; 119, List the name, no of chars of which is—no. of emp's in any other Dept. A) select * from dept d where length(dname) in (select count(*) from emp Where ddeptno <> deptno group by deptno }; (at) By select * from dept where lengih(dname) ~ any (select couni(*) from emp where d.depino <> deptno group by depno}, ) select * from dept d, (select couni(*) s,e.deptno "M"from emp e group by edepino) dl Where lengih(dname}=d1 s and dl.M- empno); 124, List the details of the emps whose Grade is equal to one tenth of Sales Dept. A) select * from amp e,salgrade s where e-sal between 5 losal and s.hisal and s.grade= 0.1" (select deptno from dept where dname ="SALES'), 125, List the name of the dept where more than average no, of emps are working. A) select d.dname from dept d, emp e where e.deptna = ddeptno group by ddhame having count(*) > (select avgicount{*)) from emp group by deptno), 126, List the Managers name who is having max no.of emps working under him. A)select m.ename,count(*) from emp w.emp m where wangr = m.empno group by mename Having com) (Gloctmax{coun(") fom orp prorp by mgs) (OR) B)select * from emp where empno = (select mgr from emp group by mar having count(*)= (sclest max(souni(*)} from emp group by mgr)) 5 127, List the Ename and Sal is increased by 15% and expressed as no.of Dollars. A) select enameto. char( 1.1 5*sal,$90,999) as "SAL" from emp; (only for it works) B) select ename;S'j1.15*sal “SAL” from emp; 128, Produce the output of EMP table ‘EMP_AND_ JOB" for Ename and Job, A) select enamelj job as "—EMP_AND_JOB" fromemp ; 129, Produce the following output ffom EMP. EMPLOYEE ‘SMITH (clerk) ALLEN (Salesman) A) select ename || *("| lowertjob)|')' as “EMPLOYEE” from emp; 130) List the emps with Hire date in format June 4, 1988, A) select empno,ename,sal, to_char(hiredate"MONTH DD.YYYY") from emp; 131) Print alist of emp's Listing ‘just salary" if Salary is more than 1500, on target if Salary is 1500 and ‘Below 1500" if Salary is less than 1500. ‘A) select empno.enamesall| “JUST SALARY’ "SAL" from emp where sal > 1500 union select empno,ename, sal ‘ON TARGET’ "SAL" from emp where sal = 1500 union select empho.ename, sall| ‘BELOW 1500' "SAL" from emp where sal < 1500; (OR) B)select empno.ename.sal,job, ‘when sal = 1500 then'ON TARGET ‘when sal < 1500 then ‘BELOW 1500" when sal> 1500 then JUST SALARY” else ‘nothing’ end "REVISED SALARY" from emp; 132) Write a query which return the day of the week for any date entered in format “DD-MM-YY". A) select to_char(to_date(‘& s\'dd-mm-yy’),'day’) from dual ; 133) Write a query to calculate the length of service of any employee with the company, use DEFINE to avoid repetitive typing of functions. A) DEFINE. service = ((months_between(syslate,hiredate))/! 2) B) Select empno.ename,&service from emp where ename=*& name"; 134) Givea string of format ‘NN/NN’. verify that the first and last two characters are numbers and that the middle character is’/", Print the expression “YES’ if valid, ‘NO’ if not valid. Use the following values to test your solution, +1234" 01a’, 99/98" A) 135) Emps hired on or before 15* of any month are paid on the last Friday of that month those hired afier 15" are paid on the first Friday of the following month, Print a list of emps their hire date and the first pay date. Sort on hire date. A) select ename hiredatenext day(last_day(hiredate),FRIDAY')-7 from emp where to_char{hiredate,DD’)<=15 union select erame,hiredate,next_day(last_day(hiredate) FRIDAY") from emp where to char(hiredate,DD)> 15; 136) Count the no, of charscters with out considering spaces for each name. A) select length(replace(ename,’ ‘ null) from emp; 137) Find out the emps who are getting decimal value in their Sal without using like operator. A) select * from emp where instr(sal,’.",1,1) > 0; 138) List those emps whose Salary coninins first four digit of their Deptno. A) select * from emp where insr(to_char(sal,,9999),deptno,1,1>0 and instr(to_char(sal,9999),deptno,| 2)> 0; 139) List those Managers who are getting less than his emps Salary. A) select distinct menameym.sal from emp wemp m where w.mgr = mampno and w.sab>msal: By select * from emp w where sal < any ( select sal from emp where ‘weempno-mgr: C) select * fromemp w where empno in ( select mgr from emp where w.sak= 36000) oF (¢.job ! “CLERK")) 149) Find out the Job that was filled in the first half of 1983 and same job that was filled during the same period of 1984, A) sdect * from cmp where (to_charthiredate/MM ‘) <= 06 and to_char(hiredate,Y YYY") = 1984) and job in (select job from emp where to_char(hiredate,’M M’ } <= 06 and to_char(hiredate’YYYY") <= 1983): 150) Find out the emps who joined in the company before their Managers. A) select * fromemp w,emp m where w.mgr = m.empno and wihiredate< mhiredate;(or) B) select * from emp e where hiredate < (select hiredate from emp where ‘empno = emgr) 151) List all the emps by name and number along with their Manager's name and number, Also List KING who has no ‘Manager’. A) select w.empno,w.ename,mempno,m.ename from emp wemp m where wamgr= mempno( +), 152) Find all the emps who earn the minimum Salary for each job wise in ascending order. A) select * ftom emp where sal in {select min(sal) from emp group by job) order by sal asc: 153) Find out all the emps who eam highest salery in each job type, Sor in descend ing salary order, A) select * fromemp where sal in (Select max(sal) from emp group by job) order by sal dese; a 154) Find out the most recently hired emps in each Dept order by Hiredate, A) select * fromemp ¢ where hiredate in (select manthiredate) from emp where edeptno= depino ) order by hiredate: 155) List the employce nameSalary and Depino for ench employee who cams a salary greater than the average for their department order by Deptno. A) select * fromempe where sal > (select avg(sal) from emp where ¢.deptno = deptno ); B) select eename.e.siledeptno from emp e,(select avg{sal) A.depino D from. emp group by depino ) DI where D1.D = edepino and e.sal > DIA; 156) List the Deptno where there are no emps. A) select deptno .count(*) from emp group by deptno having count(*) =0; 157) List the No.of emp's and Avg salary within each department for each job. A) select count(*).avg(sa),deptno, job from emp group by depinojob; 158) Find the maximum average salary drawn for each job except for “President” A) select max(avg(sal)) from emp where job != "PRESIDENT group by job; 159) Find the name and Job of the emps who earn Max salary and Commission. A) select * from emp where sal = (select max(sal) from emp) and comm. is ot null; 160) List the Name, Job and Salary of the emps who are not belonging to the department 10 but who have the same job and Salary as the emps of dept 10. A) select cname,job.sal from emp where deptno != 10 and job in (select job from emp where deptno = 10) and sal in (select sal from emp where deptno ~ 10); 161) Listthe Depino, Name, Job, Salary and SalComm of the SALESMAN who are ‘eaming maximum salary and commission in descending order. Ajselect deptno,name,job,sal.sal+nvi(comm,0) ftom emp where job = ‘SALESMAN’ and sal in (select max(sal+nvi(comm..0)) from emp where: comm. is not null) Order by (sal +nvi(comm..0)) dese: 162) List the Deptno, Name, Job, Salary and Sal+Comm af the emps who earn the second highest earnings (sal + comm). AA) select depino ename,saljob,sal+nvicomm,0) from emp where 2 = (select ‘count distinct salnvl(comm,0)) from emp where (e.saltnvi(comm.,0))}<{saltnvi(comm..0); 163) List the Deptno and their average salaries for dept with the average salary less than the averages forall department A) select deptnoavg(sal) from emp group by dept no having avg(sal) <(select avg(Sal) from emp); 164) List out the Names and Salaries of the emps along with their manager names and salaries for those emps who earn more salary than their Manager. A) select w.ename.w.sal,mename,m_sal from emp w.empm. where wamgr=m.empno.and w.sal >m sik; 165) List out the Name, Job, Salary of the emps in the department with the highest average salary. A) scleet * from emp where deptno in (sclect deptno from emp © having avg(sal) =(select max(ayg(sal)) fram emp group by deptno) group by deptna); 166) List the empnosal.comm. Ofemps. A) select empno,sal.comm, from emp; 167) Listthe details of the emps in the ascending order of the sal AA) select * from emp order by sal asc; 168) List the dept in the ascending order of the job and the dese order of the emps print empno, ename. A) select * from emp e order by e,job ase,e.empno dese ; 169) Display the unique dept of the emps. select * from dept where deptno in (select unique deptno from empk, 170) Display the unique dept with jobs. ‘A) select unique deptna job from emp ; 171) Display the details of the blake. A) select * from emp where ename = “BLAKE”; 172) Listall the clerks, A) select * from emp where job = “CLERK”; 173) list all the employees joined on I* may 8! A) select * from emp where hiredate = "01-MAY-81"; 174) List the empno,ename.sal,deptno of the dept 10 emps in the ascending order of salary, A) select e.empno.e.cname,c-sale,deptno from emp where e.deptno = 10 order by e.sal ase: 175) List the emps whose salaries are less than 3500, A) select * from emp where sal <3500; 176) List the empno.ename.sal of all the emp joined before | apr’, A) select e.empno ,e.ename .esal from emp where hiredate <"01-APR-81"; 177) List the emp whose annual sal is <25000 in the ase order of the sali A) select * from emp where ( 12*sal) < 25000 order by sal asc; 178) List the empno.ename,annsal.dailysal of all the salesmen in the asc ann sal A) select e.empno.e.ename ,12*sil "ANN SAL" , (12*saly365 "DAILY SAL" from emp e where ¢,job = "SALESMAN" order by "ANN SAL” ase: 179) List the empno,ename_hiredate,current date & exp in the ascending order of the exp. A) select empno,ename,hiredate,(select ——_sysdate from dual), ((months_between(sysdate hiredate))/12) EXP from emp order by EXP asc; 180) List the emps whose exp is more than 10 years. A) select * fiom emp where ((months_between(sysdate hiredate))'12) > 10; 181) List the ‘empnoename.sal, TAS0%DA 40% HRA 50% GROSS, LIC PF,net,deduction net allow and net sal in the ascending order of the net salary. 182) List the emps who are working as managers, A) select * from emp where job = *MANAGER"; 183) List the emps who are either clerks or managers. A) select * from emp where jab in (*CLERK’,’MANAGER’); 184) List the emps who have joined on the following dates 1 may 81.17 nov 81.30 dee 81 A) select * from emp where to_char(hiredate,"DD-MON-YY") in (’O1-MAY-81°,°17-NOV-81','30-DEC-81"}, 185) List the emps who have joined in the year 1981 A) select * from emp where to_char(hiredate,"YYY Y")= "1981"; 186) Listthe emps whose annual sal ranging from 23000 to 40000, A) select * from emp where ( 12* sal) between 23000 and 40000; 187) List the emps working under the mgrs 7369,7890,7654, 7900, A) select * from emp where mgr in ( 7369,7890,7654,7900), 188) List the emps who joined in the second half of 82. ‘A)select * from emp where hiredate between *O1-JUL-82° and ‘31-DEC-82"; 189) List all the 4char emps. AA) select * from emp where length (ename) 4 190) List the emp names starting with ‘M’ with 5 chars. A) select * from emp where ename like *M%"' and length (ename) = 5; 101) List the emps end with “H’ all together 5 chars. A) select * fromemp where ename like ‘%H" and length (ename}= 5; 192) List names start with *M’. A) select * from emp where ename like *M96"; 193) List the emps who joined in the year 8 1. ‘A) select * from emp where to_char(hiredate,"¥Y")= "81": 194) List the emps whose sal is ending with 00. fh rs 195) List the emp who joined in the month of JAN. ‘A) select * fromemp where to_char(hiredate,’MON") B) select * fromemp where to_char (hiredate,"MM") = 196) Who joined in the month having char a’. A) select * fiomemp where to_char (hiredste,"MONTH’) like"®%A%"; (OR) B) select * fromemp where instr(to_char(hiredate,’MONTH"),"A')>0; 197) Who joined in the month having second char ‘a’ A) select * fromemp where to_char(hirediate,’ MON’) like * B) select * fromemp where instr(to_char( hiredate,’MON")"A' ‘6; (OR) 2; 198). List the emps whose salary is 4 digit number. A) select * fromemp where length (sal) = 4(OR) B) select * fromemp where sal between 999 and 9999; 199) List the emp who joined in 80's. A) select * from emp where to_char(hiredate,"YY") between “80" and "89"; (OR) B) select * from emp where t0_char(hiredate,"YY") >= “80° and to_char(hiredate,"VY") < "90"; 200) List the emp who are clerks who have exp more than Bys. A) select * from emp where job = ‘CLERK’ and {months_between(sysdate hiredate) /12)> 8 201) List the mers of dept 10 or 20, A) select * from emp where job = ‘MANAGER’ and (deptno = 10 or deptna =20}; 202) List the emps joined in jan with salary ranging from 1500 to 4000. A) select * fromemp where to_char(hiredate,’MON’) ="JAN' and sal between 1500 and 4000; 203) List the unique jobs of dept 20 and 30 in dese order A) select distinct job from emp where deptno in (20,30) order by job dese; 204) List the emps along with exp of those working under the mgr whose number is starting with 7 but should not have a 9 joined before 1983. A) select * fromemp where (mgr like 7% and mgr tot like 96) and to_charfhiredate YY") <"83' 205) List the emps who are working as either mgr or analyst with the salary ranging from 2000 to 5000 and with out comm. A) select * fom emp where (job in (*MANAGER" ,'ANALYST’) ) and sal between 2000 and 5000 and comm is null; 206) List the empno,ename.sal job of the emps with /ann sal <34000 but receiving some comm, Which should not be>sal and desg should be sales man working for dept 30. A) select empno,ename,saljob from emp where 12%(sal+vi{comm.0)) = 34000 and comm is not null and comm-sal and job = SALESMAN’ and depino = 30; 207) List the emps who are working for dept 10 or 20 with desgs as clerk or analyst with a sal is either 3 or 4 digits with an exp> 8ys but does not belong to mons of imar.apr sep and working for mgrs Ano is not ending with 88 and 56. A) select * from emp where deptno in (10,20) and job in(CLERK''ANALYST) and ength(sal) in (3.4) and {(vepnths_between(sysdate hiredate))/1 2)> 8 and to_char(hiredateMON’) not in (MAR"’SEP’ APR’) and (mgr not like 88 and mgr not like 656), 208) List the empno,ename,sal, job depino&exp of all the emps belongs to dept 10 or 20 with an exp 6 to 10 y working under the seme mgr with out comm, With a job not ending irrespective of the position with comm.>200 with exp>—7y and 4 ‘sa<2500 but not belongs to the month sep or now working_under the mar whose no is not having digits either 9 or 0 in the ase deptde dese dept A) 209) Listthe details of the emps working at Chicago. AA) select * from emp where dapins in (sles dept from dept where dept oc = *CHICAGO"); 210) List the empno.ename,depino Joc of all the emps. A) select e-empno..cname,e-deptno.d.lac from emp e dept d ‘where edeptno = ddeptno : 211) Listthe empno,ename,loc,dname of all the depts.,10 and 20, A) select e.empno.e-ename,e.deptno,dlocd.dname from emp e dept d where edeptno= ddeptno and e.deptno in (10.20); 12) List the empno, ename, sal, lee of the emps working at Chicago dallas with an exp>bys, A) select cempno.e.ename,edepino,e-sald.loc from emp e dept d where edeptno = d.depino and dloc in (CHICAGO DALLAS) and (months. between(sysdate;hiredate)/12)> 6 ; 213) List the emps along with loc of those who belongs to dallas ;newyork with sal ranging from 2000 to 5000 joined in 81. A) select e.empno,e.ename,edepino,e-sal.d.loc from emp e dept d ‘where edepino ~ d.depino and d.loc in (‘NEW YORK',DALLAS') and to_char(ehiredate’YY")='81° and e-sal between 2000 and 5000, 214) Listthe empno.ename,sal, grade of all emps. A) select cempno.e-ename,esals.grade from emp ¢ salgrade + where esal between s.losal and sisal ; 215) Listthe grade 2 and 3 emp of Chicago. A) select * fromemp where empno in (select cmpno from emp ¢,salgrade s where ¢.sal between s.losal and schisal and s.grade in (2,3)): 216) List the emps with loc and grade of sccounting dept or the locs dallas or Chicago with the grades 310 5 &exp>6y A) select edepinoe.empno.e.nmme.e.sal,ddname,d.loc.s.grade from emp cesalgrade dept d wheree.depino = ddeptno and e-sal between s.Josal and s.hisal and s grade in (3,5) and ((months_between(sysdate,hiredate)y/12) >6 and (d.dname = ‘ACCOUNTING’ or D.loc in (DALLAS CHICAGO), 217) List the grades 3 emps of research and operations depts. joined after 1987 and whose names should not be either miller or allen. A) select eename from empe dept d.salgrade s where edepino = ddeptno and d.dname in (OPER ATIONS' ‘RESEARCH ) and e.sal between s losal and s.hisal and e,cname not in (MILLER"ALLEN') and 1o_charfhiredate."°YYYY) > 1987; 218) List the emps whose job is same as smith, A) select * fiom cmp where job = (select job from emp where ename = SMITH’), 219) List the emps who are senior to miller. A) seloct_* from emp where _hinedate