You are on page 1of 4

(Outputs in EOP)

1.
select ename,sal,'UnderPaid' As Status
from emp_sample
where sal <= 2000
UNION
select ename,sal,'OverPaid' As Status
from emp_sample
where sal >= 4000
UNION
select ename,sal,'Ok' As Status
from emp_sample
where sal between 2001 and 3999

2.
Select ename,REGEXP_REPLACE(Ename,'[A,E,I,O,U]')AS NEW_NAME,sal ,REPLACE(Sal,'0')AS
NEW_SAL FROM EMP_SAMPLE

3.

select e1.ename ||' works for '||e2.ename Emp_and_Mgr


from emp_sample e1,emp_sample e2
where e1.mgr=e2.empno

4.

5.

select Distinct e2.ename Mgr_Name ,e2.job


from emp_sample e1,emp_sample e2
where e1.mgr=e2.empno and e2.job not in 'PRESIDENT'

6.

select max(mgr_count)
from(select mgr,count(mgr) mgr_count
from emp_sample
group by mgr)

7.

select e1.ename Mgr_name,e1.sal Mgr_Sal,e2.ename Emp_name,e2.sal Emp_sal


from emp_sample e1,emp_sample e2
where e1.empno=e2.mgr and e2.sal > e1.sal
(or)

select e1.ename Emp_name,e1.sal Emp_Sal,e2.ename Mgr_name,e2.sal Mgr_sal


from emp_sample e1,emp_sample e2
where e1.mgr=e2.empno and e2.sal< e1.sal

8.
create view Long_term_emp As
select e1.ename Emp_Name ,e1.hiredate Emp_hiredate,e2.ename Mgr_Name ,e2.hiredate
Mgr_Hiredate
from emp_sample e1,emp_sample e2
where e1.mgr=e2.empno and e1.hiredate < e2.hiredate

9.
select sal
from( select rownum slno,sal
from(select distinct(sal)
from emp_sample
order by sal asc) )
where slno <=5

(or)

select top 5 sal


from (select disedtinct(sal)
from emp_sample
order by sal ASC)

10.

select ename ,job ,deptno


from emp_sample
where job in (select job
from emp_sample
where deptno in 30) and deptno in 10

--------------------------------------------------------------------1.

ENAME SAL STATUS


---------- ---------- ---------
ADAMS 1100 UnderPaid
ALLEN 1600 UnderPaid
BLAKE 2850 Ok
CLARK 2450 Ok
FORD 3000 Ok
JAMES 950 UnderPaid
JONES 2975 Ok
KING 5000 OverPaid
MARTIN 1250 UnderPaid
MILLER 1300 UnderPaid
SCOTT 3000 Ok
SMITH 800 UnderPaid
TURNER 1500 UnderPaid
WARD 1250 UnderPaid

2.
NEW_NAME NEW_SAL
---------- ------
KNG 5
BLK 285
CLRK 245
JNS 2975
SCTT 3
FRD 3
SMTH 8
LLN 16
WRD 125
MRTN 125
TRNR 15
DMS 11
JMS 95
MLLR 13

3.

EMP_AND_MGR
--------------------------
JONES works for KING
CLARK works for KING
BLAKE works for KING
JAMES works for BLAKE
TURNER works for BLAKE
MARTIN works for BLAKE
WARD works for BLAKE
ALLEN works for BLAKE
MILLER works for CLARK
FORD works for JONES
SCOTT works for JONES
ADAMS works for SCOTT
SMITH works for FORD

4.

5.

MGR_NAME JOB
---------- ---------
CLARK MANAGER
JONES MANAGER
SCOTT ANALYST
FORD ANALYST
BLAKE MANAGER

6.
MAX(MGR_COUNT)
--------------
5

7.
MGR_NAME MGR_SAL EMP_NAME EMP_SAL
---------- ---------- ---------- ----------
JONES 2975 SCOTT 3000
JONES 2975 FORD 3000

8.

EMP_NAME EMP_HIRED MGR_NAME MGR_HIRED


---------- --------- ---------- ---------
JONES 02-APR-81 KING 17-NOV-81
CLARK 09-JUN-81 KING 17-NOV-81
BLAKE 01-MAY-81 KING 17-NOV-81
WARD 22-FEB-81 BLAKE 01-MAY-81
ALLEN 20-FEB-81 BLAKE 01-MAY-81
SMITH 17-DEC-80 FORD 03-DEC-81

9.

SAL
----
800
950
1100
1250
1300

10.

ENAME JOB DEPTNO


---------- --------- ----------
CLARK MANAGER 10
MILLER CLERK 10

(jobs from dept 30 -manager,salesman,clerk)

You might also like