The table script and data script for employee, dept, salgarade is available at DB Script
A: Select * from dept
A: Select * from emp
A: Select ename, job from emp
A: Select ename, sal from emp
A: Select empno, sal+nvl(comm, 0) from emp
A: Select ename, 12*sal as annualsal from emp
A: Select ename from emp where deptno=10
A: Select ename from emp where job='CLERK' and sal > 1000
A: Select empno, ename from emp where comm is not null
A: Select ename from emp where comm is null
A: Select ename from emp where job in ('CLERK','SALESMAN','ANALYST') and sal>2000
A: Select ename from emp where (months_between(sysdate, hiredate)/12)>30
A: Select ename from emp where (hiredate < '30-Jun-90') or hiredate > '31-JUN-90'
A: Select sysdate from dual
A: Select ename from emp where deptno in (10,20,40) or job in('CLERK','SALESMAN','ANALYST')
A: Select ename from emp where ename like 'S%'
A: Select ename from emp where ename like '%S'
A: Select ename from emp where ename like '_A%'
A: Select ename from emp where length(ename)=5
OR
A: Select ename from emp where ename like '_____'
A: Select * from emp where job <> 'MANAGER'
OR
A: Select * from emp where job != 'MANAGER'
A: Select * from emp where job not in ( 'SALESMAN','ANALYST','CLERK')
A: Select count(*) from emp
A: Select sum(sal)+sum(nvl(comm,0)) totalSAL from emp
A: Select max(sal) from emp
A: Select min(sal) from emp
A: Select avg(sal) from emp
A: Select max(sal) from emp where job=’CLERK’
A: Select max(sal) from emp where deptno=20
A: Select min(sal) from emp where job=’SALESMAN’
A: Select avg(sal) from emp where job=’MANAGER’
A: Select sum(sal) from emp where deptno=20 and job='ANALYST'
A: Select ename from emp order by sal
A: Select ename from emp order by sal desc
A: Select * from emp order by ename
A: Select empno,ename,deptno,sal from emp order by ename,deptno,sal
A: Select ename, (sal*12) from emp
A: Select ename,(sal*15)/100 hra,(sal*10)/100 da,(sal*5)/100 pf, (sal*(sal*0.15)*(sal*0.10))-sal*0.05 totalsalary from emp
A: Select DEPTNO,count(DEPTNO) from emp group by deptno
A: Select job,count(job) from emp group by job
A: Select deptno, sum(sal) totalsal from emp group by deptno
A: Select deptno, max(sal) maxsal from emp group by deptno
A: Select job, sum(sal) totalsal from emp group by job
A: Select job, min(sal) minsal from emp group by job
A: Select deptno, count(deptno) from emp group by deptno having count(deptno)>3
A: Select job, sum(sal) totalsal from emp group by job having sum(sal)>8000
A: Select job, count(job) from emp group by job having count(job)>3
A: Select ename from emp where sal = (select max(sal) from emp)
A: Select empno,ename from emp where job='CLERK' and sal=(select max(sal) from emp where job='CLERK')
A: Select empno,ename from emp where job='SALESMAN' and sal=(select max(sal) from emp where job='CLERK')
A: Select empno,ename from emp where job='CLERK' and sal>(select sal from emp where ename='JAMES') and sal<(select sal from emp where ename='SCOTT')
A: Select ename from emp where sal>(select sal from emp where ename='JAMES') or sal<(select sal from emp where ename='SCOTT')
A: Select ename from emp e where sal=(select max(sal) from emp where deptno= e.deptno)
A: Select ename from emp e where sal=(select max(sal) from emp where job= e.job)
A: Select ename from emp where deptno=(select deptno from dept where dname='ACCOUNTING')
A: Select ename from emp where deptno=(select deptno from dept where loc='CHICAGO')
A: Select job,sum(sal) from emp group by job having sum(sal)> (select max(sal) from emp where job='MANAGER')
A: Select ename, sal from emp WHERE deptno=10 and sal=(select max(sal) from emp)
A: Select ename, sal from emp where deptno = 10 and sal > all(select sal from emp where deptno !=10)
A: Select upper(ename) from emp
A: Select lower(ename) from emp
A: Select initcap(ename) from emp
A: Select length('naga') from dual
A: Select ename,length(ename) from emp
A: Select concat(empno, ename) from emp
A: Select substr('oracle',2,3) from dual
A: Select instr('computer maintenance corporaton','a',1,1) from dual
A: Select replace('allen’s','a','b') FROM dual
A: Select ENAME, replace('BOSS','MANAGER') FROM emp where job='MANAGER'
A: Select empno,ename,decode(deptno,10,'ACCOUNTING',20,'RESEARCH',30,'SALES') from emp
A: Select months_between(sysdate,'15-june-1985')*30 from dual
A: Select months_between(sysdate,'15-june-1985') from dual
A: Select replace('15-aug-1947',sysdate) from dual
A: Select ename || 'has joined the company on' || to_char(hiredate,'ddth month day year') FROM emp
A: Select next_day(sysdate,'saturday') from dual
A: Select to_char(sysdate,'hh:mi:ss') from dual
A: Select sysdate-90 FROM dual
A: Select job from emp where deptno=20 INTERSECT select job from emp where deptno=10
A: Select DISTINCT job from emp where deptno in(10,20)
A: Select job FROM emp where job not in (select job from emp WHERE deptno in (20,30,40))
OR
A: Select job FROM emp WHERE deptno=10 and job not in (SELECT job FROM emp where deptno <> 10)
A: Select * from emp where empno not in (select empno FROM emp where empno in (select mgr FROM emp))
OR
A: Select * from emp where empno not in (Select DISTINCT mgr from emp where mgr is not null)
A: Select ename,dname,grade from emp,dept,salgrade where emp.deptno=dept.deptno and dname='SALES' and sal between losal and hisal and grade=3
A: Select* from emp where empno in (select mgr from emp)) INTERSECT (select * from emp where empno not in (select empno from emp where empno in (select mgr from emp))
A: Select * FROM emp where length(ename) > 4
A: Select * FROM dept where dname like 'S%' and loc like '%O'
A: Select * from emp where mgr in (select empno from emp WHERE ename='JONES')
A: Select ename from emp where sal+(sal*0.2) > 3000
A: Select e.ename, d.dname from emp e, dept d where e.deptno= d.deptno
A: Select e.ename from emp e, dept d where e.deptno= d.deptno and d.dname='SALES'
A: Select e.ename, d.dname,e.sal,e.comm from emp e, dept d where e.deptno= d.deptno and d.loc='CHICAGO' and e.sal between 2000 and 5000
A: Select * from emp e1 where e1.sal>(select e2.sal from emp e2 where e1.mgr= e2.empno)
A: Select * from emp e1 where e1.deptno=(select e2.deptno from emp e2 where e1.mgr= e2.empno)
A: Select ename from emp where mgr is null
A: Select grade,ename from emp, salgrade where grade!=4 and deptno in (10,30) and hiredate < to_date('31-dec-82') and sal BETWEEN losal and hisal
A: Update emp set sal=sal+sal*0.1 where comm is null
A: Select * from emp e, dept d where e.hiredate<'31-dec-82' and e.deptno= d.deptno and (d.loc='NEWYORK' or d.loc='CHICAGO')
A: Select e.ename,e.job,d.dname,d.loc from emp e,dept d where e.deptno= d.deptno and e.job='MANAGER'
A: Select e.ename, e.mgr MGRNO, e1.ename MGRNAME from emp e, emp e1 where e.mgr=e1.empno and e1.ename='JONES'
A: Select ename, sal, grade, hisal from emp, salgrade where ename='FORD' and sal=hisal and sal between losal and hisal
A: Select e.ename,e.job,d.dname, grade, e1.ename from emp e,emp e1,dept d, salgrade where e.deptno= d.deptno and e.mgr=e1.empno and e.sal between losal and hisal
A: Select ename,job,sal,grade from emp,dept,salgrade where emp.deptno= dept.deptno and sal between losal and hisal and job<>'CLERK' order by sal desc
A: Select e.ename,e.job,e1.ename MGRNAME from emp e, emp e1 where e.mgr=e1.empno(+)
A: Select e.ename from emp e where 5>(select count(*) from emp e1 where e.sal>e1.sal)
A: Select ename from emp where sal=(select max(sal) from emp)
Tags : Sample DB queries for practice. Oracle queries, employee, dept, salgrade tables, table scripts