1. EMP Å×ÀÌºí¿¡¼­ ¾Æ·¡ÀÇ °á°ú¸¦ Ãâ·ÂÇÏ´Â SELECT ¹®ÀåÀ» ÀÛ¼ºÇÏ¿©¶ó. H_YEAR COUNT(*) MIN(SAL) MAX(SAL) AVG(SAL) SUM(SAL) ------ --------- --------- --------- --------- --------- 80 1 800 800 800 800 81 10 950 5000 2282.5 22825 82 1 1300 1300 1300 1300 87 2 1100 3000 2050 4100 select to_char(hiredate,'yy') "H_YEAR",count(*),min(sal),max(sal),avg(sal),sum(sal) from emp group by to_char(hiredate,'yy') 2. EMP Å×ÀÌºí¿¡¼­ ¾Æ·¡ÀÇ °á°ú¸¦ Ãâ·ÂÇÏ´Â SELECT ¹®ÀåÀ» ÀÛ¼ºÇÏ¿©¶ó. TOTAL 1980 1981 1982 1987 --------- --------- --------- --------- --------- 14 1 10 1 2 select count(*) "TOTAL", count(case when to_char(hiredate,'yyyy')='1980' then 'a' end) "1980", count(case when to_char(hiredate,'yyyy')='1981' then 'a' end) as "1981 ³â", count(case when to_char(hiredate,'yyyy')='1982' then 1 end) as "1982", count(case when to_char(hiredate,'yyyy')='1987' then 1 end) as "1987" from emp; select count(*) "TOTAL", count(decode(to_char(hiredate,'yyyy'),'1980','a') ),.... from emp; 3. EMP Å×ÀÌºí¿¡¼­ ¾Æ·¡ÀÇ °á°ú¸¦ Ãâ·ÂÇÏ´Â SELECT ¹®ÀåÀ» ÀÛ¼ºÇÏ¿©¶ó. select job,sum(decode(deptno,10,sal)) "Deptno 10", sum(decode(deptno,20,sal)) "Deptno 20",sum(decode(deptno,30,sal)) "Deptno 30",sum(sal) "Total" from emp group by job; select job,sum(case when deptno=10 then sal end) "Deptno 10", 4.select mgr,job,sum(sal) from emp group by rollup(mgr,job) order by mgr; 5.select deptno,avg(sal),sum(sal) from emp group by deptno having max(sal)>2900; 6.select e.ename,e.job,e.sal,d.dname from emp e,dept d where e.deptno=d.deptno and d.loc='NEW YORK'; 7.select e.ename,e.job,d.dname,d.loc from emp e,dept d where e.ename like '%L%' and e.deptno=d.deptno; 8.select e.ename,e.job,e.sal,s.grade,d.dname,d.loc from emp e,dept d,salgrade s where e.deptno=d.deptno and e.sal between s.losal and s.hisal; 9.select e.empno "Emp#",e.ename "Employee",m.empno "Mgr#",m.ename "Manager" from emp e,emp m where m.empno(+)=e.mgr; 10.select e.ename "»ç¿øÀ̸§",e.hiredate "°ü¸®ÀÚÀ̸§",m.ename "°ü¸®ÀÚÀ̸§",m.hiredate "°ü¸®ÀÚÀÔ»çÀÏ" from emp e,emp m where e.mgr=m.empno and e.hiredate(select avg(sal) from emp) order by sum(sal) desc 3. EMP Å×ÀÌºí¿¡¼­ À̸§¿¡ ¡°T¡±°¡ ÀÖ´Â »ç¿øÀÌ ±Ù¹«ÇÏ´Â ºÎ¼­¿¡¼­ ±Ù¹«ÇÏ´Â ¸ðµç »ç¿ø¿¡ ´ëÇØ »ç¿ø ¹øÈ£,À̸§,±Þ¿©¸¦ Ãâ·ÂÇÏ´Â SELECT¹®À» ÀÛ¼ºÇϽÿÀ. ´Ü »ç¿ø¹øÈ£ ¼øÀ¸·Î Ãâ·ÂÇÏ¿©¶ó. select empno,ename,sal from emp where deptno in (select deptno from emp where ename like '%T%') order by empno; 4. EMP Å×ÀÌºí¿¡¼­ ºÎ¼­ À§Ä¡°¡ DallasÀÎ ¸ðµç »ç¿ø¿¡ ´ëÇØ À̸§,¾÷¹«,±Þ¿©¸¦ Ãâ·ÂÇÏ´Â SELECT¹®À» ÀÛ¼ºÇϽÿÀ. select ename,job,sal from emp where deptno=(select deptno from dept where loc='DALLAS'); 5. EMP Å×ÀÌºí¿¡¼­ King¿¡°Ô º¸°íÇÏ´Â ¸ðµç »ç¿øÀÇ À̸§°ú ±Þ¿©¸¦ Ãâ·ÂÇÏ´Â SELECT¹®À» ÀÛ¼ºÇϽÿÀ. select ename,sal from emp where mgr=(select empno from emp where ename='KING'); 6. EMP Å×ÀÌºí¿¡¼­ SALES ºÎ¼­ »ç¿øÀÇ À̸§,¾÷¹«¸¦ Ãâ·ÂÇÏ´Â SELECT¹®À» ÀÛ¼ºÇϽÿÀ. select ename,job from emp where deptno=(select deptno from dept where dname='SALES'); 7. EMP Å×ÀÌºí¿¡¼­ FORD¿Í ¾÷¹« ¹× ¿ù±ÞÀÌ °°Àº »ç¿øÀÇ ¸ðµç Á¤º¸¸¦ Ãâ·ÂÇÏ´Â SELECT¹®À» ÀÛ¼ºÇϽÿÀ.(°á°ú¿¡¼­ FORD´Â Á¦¿Ü) select * from emp where (job,sal) in (select job,sal from emp where ename='FORD') and not ename = 'FORD'; 8. EMP Å×ÀÌºí¿¡¼­ ¾÷¹«°¡ JONES¿Í °°°Å³ª ¿ù±ÞÀÌ FORDÀÌ»óÀÎ »ç¿øÀÇ À̸§,¾÷¹«,ºÎ¼­¹øÈ£,±Þ¿©¸¦ Ãâ·ÂÇÏ´Â SELECT¹®À» ÀÛ¼ºÇϽÿÀ. ´Ü ¾÷¹«º°, ¿ù±ÞÀÌ ¸¹Àº ¼øÀ¸·Î Ãâ·ÂÇÏ¿©¶ó. select ename,job,deptno,sal from emp where job=(select job from emp where ename='JONES') or sal>=(select sal from emp where ename='FORD') order by job,sal desc; 9. EMP Å×ÀÌºí¿¡¼­ SCOTT ¶Ç´Â WARD¿Í ¿ù±ÞÀÌ °°Àº »ç¿øÀÇ À̸§,¾÷¹«,±Þ¿©¸¦ Ãâ·ÂÇÏ´Â SELECT¹®À» ÀÛ¼ºÇϽÿÀ.(SCOTT,WARD´Â Á¦¿Ü) select ename,job,sal from emp where sal in (select sal from emp where ename in ('SCOTT','WARD'); 10. EMP Å×ÀÌºí¿¡¼­ CHICAGO¿¡¼­ ±Ù¹«ÇÏ´Â »ç¿ø°ú °°Àº ¾÷¹«¸¦ ÇÏ´Â »ç¿øÀÇ À̸§,¾÷¹«¸¦ Ãâ·ÂÇÏ´Â SELECT¹®À» ÀÛ¼ºÇϽÿÀ. select ename,job,deptno from emp where job in (select job from emp where deptno = (select deptno from dept where loc='CHICAGO')) and deptno != (select deptno from dept where loc='CHICAGO'); 11. EMP Å×ÀÌºí¿¡¼­ ¿ù±ÞÀÌ ÀÚ½ÅÀÌ ¼ÓÇÑ ºÎ¼­ÀÇ Æò±Õ ¿ù±Þº¸´Ù ³ôÀº »ç¿øÀÇ ºÎ¼­¹øÈ£,À̸§,±Þ¿©¸¦ Ãâ·ÂÇÏ´Â SELECT¹®À» ÀÛ¼ºÇϽÿÀ. select e.deptno,e.ename,e.sal,d.deptno,d.d_sal from emp e,(select deptno ,avg(sal) d_sal from emp group by deptno) d where e.deptno=d.deptno and e.sal >d.d_sal order by d.d_sal; 12. EMP Å×ÀÌºí¿¡¼­ 30¹ø ºÎ¼­¿ø Áß ÃÖÀú±Þ¿©¸¦ ¹Þ´Â »ç¿øÀ» Á¦¿ÜÇÑ ³ª¸ÓÁö »ç¿øµéÀÇ ¸ðµç Á¤º¸¸¦ Ãâ·ÂÇÏ´Â SELECT¹®À» ÀÛ¼ºÇϽÿÀ. select * from emp where deptno=30 and sal>(select min(sal) from emp where deptno=30); 13. EMP Å×ÀÌºí¿¡¼­ Àû¾îµµ ÇÑ ¸í ÀÌ»óÀ¸·ÎºÎÅÍ º¸°í¸¦ ¹ÞÀ» ¼ö ÀÖ´Â »ç¿øÀÇ ¾÷¹«,À̸§,»ç¿ø¹øÈ£,ºÎ¼­¹øÈ£¸¦ Ãâ·ÂÇÏ´Â SELECT¹®À» ÀÛ¼ºÇϽÿÀ.(´Ù¸¥ »ç¿øÀ» °ü¸®ÇÏ´Â »ç¿ø) select * from emp where empno in (select mgr from emp); 14. EMP Å×ÀÌºí¿¡¼­ ¸»´Ü »ç¿øÀÇ »ç¿ø¹øÈ£,À̸§,¾÷¹«,ºÎ¼­¹øÈ£¸¦ Ãâ·ÂÇÏ´Â SELECT¹®À» ÀÛ¼ºÇϽÿÀ.(¸»´Ü»ç¿ø: ´Ù¸¥ »ç¿øÀ» °ü¸®ÇÏÁö ¾Ê´Â »ç¿ø) select * from emp where empno not in (select nvl(mgr,-1) from emp); select * from emp where empno not in (select mgr from emp where mgr is not null); select count(*) from emp where mgr is null; select * from emp e where not exists (select 'a' from emp m where e.empno = m.mgr);