You are on page 1of 3

# Excercises 1) Display according to the following format Employee – works in – Deptno Smith – works in – 20 select ename,' Works in ',deptno

from emp 2) display distinct values of dept no from emp select DISTINCT deptno from dept; 3)display employee details ordered by dept no with lates hiredate displayed first select * from emp ORDER BY deptno,hiredate desc; 4) display the employee details whose comm. Is greater than sal. select * from emp where sal < comm ; 5) display all employees who have been hired from feb to oct 1981. select * from emp where hiredate BETWEEN '01-FEB-1981' AND '31-OCT1981' 6) display all employee names which have either TH or LL. select ename from emp where ename LIKE '%TH%' OR ename LIKE '%LL%' ; 7) produce the following o/p -Employee left aligned and job right aligned. Employee _AND_ Job Smith Clerk select CONCAT(RPAD(ename,10,' '), LPAD(job,10,' ') ) AS EMPLOYEE_AND_JOB from emp 8) display the number of times ‘s ‘ appears in a dept name. select dname ,(LENGTH(dname) LENGTH(TRANSLATE(dname,'AS','A'))) AS No from dept select dname ,(LENGTH(dname) - LENGTH(REPLACE(dname,'S'))) AS No from dept 9) display in the following format Employe --------SMITH (Clerk) select ename||'('||INITCAP(job)||')' AS "Employee" from emp 10) display in the following format ENAME HIREDATE SERVICE_PERIOD 29 years 9 months. select ename, hiredate, FLOOR(MONTHS_BETWEEN(sysdate,hiredate)/12)||'years and '|| MOD(FLOOR(MONTHS_BETWEEN(sysdate,hiredate)),12)||'months' AS SERVICE_PERIOD from emp 11) display in following format ENAME SAL REM

Display avg monthly salary bill for each job type within dept.ename.sal) IN (select deptno.sal.hiredate.ename. 19.sal.dname from emp e. select deptno.'on target'. select worker..sal from emp worker. find all employees as the same job as blake select ename from emp where job = (select job from emp where ename = 'BLAKE').job.sal > manager. emp manager 14) display dept name without any employess. dept d where e.decode(sign(sal-1500).AVG(sal) from emp group by job.AVG(sal) from emp GROUP BY(deptno) having count(*) > 3 18.sal. count(*). select d.manager. find whether all employee numbers are indeed unique select empno.empno and worker.MIN(SAL) from emp group by deptno) 22.hiredate from emp worker. select ename.0.deptno.ename.sal from emp where (deptno.sal from emp where sal > (select MIN(Sal) from emp where deptno=30 group by deptno .(CASE WHEN sal < 1500 THEN 'BELOW TARGET ' WHEN sal =1500 THEN 'ON TARGET' ELSE TO_CHAR(sal) END) AS REM from emp 12) display employees getting more sal than manager.worker.sal) AS REM from emp.deptno(+)=d. select deptno. List all deptmt's with at least two analyst select deptno.worker.sal 13) workers who joined before null select worker. select job. select ename. select ename. Display the avg salary for all dept's employing morethan 3 ppl.<1500 Below target 1500 on target >1500 exacrt value.'below target'.avg(sal) from emp group by deptno.deptno and e.ename.count(*) from emp where job like 'ANALYST' group by deptno having count(*) >= 2 20.manager. 16. 21. emp manager where worker.empno is null 15. display the employees who earn more than lowest sal in dept no 30. Calculate the average slalary for each different job.manager.job order by deptno 17.count(*) from emp group by empno.mgr=manager.-1. find the employees who earn the lowest sal in their dept. select ename.manager.

AVG(sal) from emp HAVING AVG(sal) = ( select MAX(AVG(sal)) from emp group by job) group by job 24. select * from (select * from (select * from emp order by sal desc) where rownum <=&n order by 1 desc ) where rownum =1 25. delete duplicate rows delete from test1 where rowid not in ( select max(rowid) from test1 group by id). select * from (select * from emp order by rownum desc ) where rownum <= &n order by 1 26. find nth highest salary. create table testnew as select * from test1 where 1=2. find the job with highest avg salary select job. 28. . 27.23. How to find last n rows of emp table. Create a table drop. Restore the first table. how to copy a structure of a table. Create the table of the same name and then drop again.