ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • SQL ์กฐ์ธ, ์„œ๋ธŒ์ฟผ๋ฆฌ ์—ฐ์Šต๋ฌธ์ œ ํ’€์–ด๋ณด๊ธฐ
    DATABASE 2020. 7. 22. 08:33

    ๐ŸŽฏ SQL Join๊ณผ ์„œ๋ธŒ์ฟผ๋ฆฌ๋ฅผ ํ™œ์šฉํ•ด ๋‹ค์–‘ํ•œ ์˜ˆ์ œ๋ฅผ ํ’€์–ด๋ณธ๋‹ค.

     

     

     

     

    JOIN ์‹ค์Šต๋ฌธ์ œ

    SCOTT ๊ณ„์ •์˜ ์—ฐ์Šต์šฉ ํ…Œ์ด๋ธ” ์‚ฌ์šฉ

    ์˜ค๋ผํด ์กฐ์ธ๋„ ์‚ฌ์šฉํ•ด๋ณด๊ณ  ANSI์กฐ์ธ๋„ ์‚ฌ์šฉํ•ด๋ณด๊ธฐ

     

     

    1. ๋ถ€์„œ ํ…Œ์ด๋ธ”๊ณผ ์‚ฌ์›ํ…Œ์ด๋ธ”์—์„œ ์‚ฌ๋ฒˆ, ์‚ฌ์›๋ช…, ๋ถ€์„œ์ฝ”๋“œ, ๋ถ€์„œ๋ช…์„ ๊ฒ€์ƒ‰ํ•˜์‹œ์˜ค. ( ์‚ฌ์›๋ช… ์˜ค๋ฆ„์ฐจ์ˆœ ์ •๋ ฌํ•  ๊ฒƒ )

     

    SELECT EMPNO, ENAME, DEPTNO, DNAME
    FROM EMP, DEPT
    ORDER BY ENAME;

     

     

    2. ๋ถ€์„œ ํ…Œ์ด๋ธ”๊ณผ ์‚ฌ์›ํ…Œ์ด๋ธ”์—์„œ ์‚ฌ๋ฒˆ, ์‚ฌ์›๋ช… , ๊ธ‰์—ฌ , ๋ถ€์„œ๋ช…์„ ๊ฒ€์ƒ‰ํ•˜์‹œ์˜ค. ๋‹จ, ๊ธ‰์—ฌ๊ฐ€ 2000 ์ด์ƒ์ธ ์‚ฌ์›์— ๋Œ€ํ•˜์—ฌ ๊ธ‰์—ฌ๊ธฐ์ค€์œผ๋กœ ๋‚ด๋ฆผ์ฐจ์ˆœ ์ •๋ ฌํ•  ๊ฒƒ.

     

     

     

    3. ๋ถ€์„œ ํ…Œ์ด๋ธ”๊ณผ ์‚ฌ์› ํ…Œ์ด๋ธ”์—์„œ ์‚ฌ๋ฒˆ, ์‚ฌ์›๋ช…, ์—…๋ฌด, ๊ธ‰์—ฌ , ๋ถ€์„œ๋ช…์„ ๊ฒ€์ƒ‰ํ•˜์‹œ์˜ค. ๋‹จ, ์—…๋ฌด๊ฐ€ Manager์ด๋ฉฐ ๊ธ‰์—ฌ๊ฐ€ 2500 ์ด์ƒ์ธ ์‚ฌ์›์— ๋Œ€ํ•˜์—ฌ ์‚ฌ๋ฒˆ์„ ๊ธฐ์ค€์œผ๋กœ ์˜ค๋ฆ„์ฐจ์ˆœ ์ •๋ ฌํ•  ๊ฒƒ.

     

     

     

    4. ์‚ฌ์› ํ…Œ์ด๋ธ”๊ณผ ๊ธ‰์—ฌ ๋“ฑ๊ธ‰ ํ…Œ์ด๋ธ”์—์„œ ์‚ฌ๋ฒˆ, ์‚ฌ์›๋ช…, ๊ธ‰์—ฌ, ๋“ฑ๊ธ‰์„ ๊ฒ€์ƒ‰ํ•˜์‹œ์˜ค. ๋‹จ, ๋“ฑ๊ธ‰์€ ๊ธ‰์—ฌ๊ฐ€ ํ•˜ํ•œ๊ฐ’๊ณผ ์ƒํ•œ๊ฐ’ ๋ฒ”์œ„์— ํฌํ•จ๋˜๊ณ  ๋“ฑ๊ธ‰์ด 4์ด๋ฉฐ ๊ธ‰์—ฌ๋ฅผ ๊ธฐ์ค€์œผ๋กœ ๋‚ด๋ฆผ์ฐจ์ˆœ์ •๋ ฌํ•  ๊ฒƒ.

     

     

    SELECT EMPNO, ENAME, SAL, GRADE
    FROM EMP E, SALGRADE S
    WHERE SAL BETWEEN LOSAL AND HISAL
    AND GRADE = 4
    ORDER BY SAL DESC;

     

     

    5. ๋ถ€์„œ ํ…Œ์ด๋ธ”, ์‚ฌ์› ํ…Œ์ด๋ธ”, ๊ธ‰์—ฌ๋“ฑ๊ธ‰ ํ…Œ์ด๋ธ”์—์„œ ์‚ฌ๋ฒˆ, ์‚ฌ์›๋ช…, ๋ถ€์„œ๋ช…, ๊ธ‰์—ฌ , ๋“ฑ๊ธ‰์„ ๊ฒ€์ƒ‰ํ•˜์‹œ์˜ค. ๋‹จ, ๋“ฑ๊ธ‰์€ ๊ธ‰์—ฌ๊ฐ€ ํ•˜ํ•œ๊ฐ’๊ณผ ์ƒํ•œ๊ฐ’ ๋ฒ”์œ„์— ํฌํ•จ๋˜๋ฉฐ ๋“ฑ๊ธ‰์„ ๊ธฐ์ค€์œผ๋กœ ๋‚ด๋ฆผ์ฐจ์ˆœ ์ •๋ ฌํ•  ๊ฒƒ.

     

    where์ ˆ์—์„œ e์™€ d์—์„œ ๊ฒน์น˜๋Š” ์ปฌ๋Ÿผ์„ ๋ช…์‹œํ•ด์ฃผ์ง€ ์•Š์œผ๋ฉด ์นดํƒ€ ์กฐ์ธ์ด ๋˜์–ด์„œ ์˜ฌ๋ฐ”๋ฅธ ๋ฐ์ดํ„ฐ๊ฐ’์„ ๋ถˆ๋Ÿฌ์˜ค์ง€ ๋ชปํ•œ๋‹ค.

     

    SELECT EMPNO, ENAME, DNAME, SAL, GRADE
    FROM EMP E, DEPT D, SALGRADE S
    WHERE E.DEPTNO = D.DEPTNO
    AND SAL BETWEEN LOSAL AND HISAL
    ORDER BY GRADE DESC;

     

     

    6. ์‚ฌ์› ํ…Œ์ด๋ธ”์—์„œ ์‚ฌ์›๋ช…๊ณผ ํ•ด๋‹น ์‚ฌ์›์˜ ๊ด€๋ฆฌ์ž๋ช…์„ ๊ฒ€์ƒ‰ํ•˜์‹œ์˜ค

     

     

    SELECT E.ENAME ์‚ฌ์›๋ช…, M.ENAME ๊ด€๋ฆฌ์ž๋ช…
    FROM EMP E, EMP M
    WHERE E.MGR = M.EMPNO;

     

     

    7. ์‚ฌ์› ํ…Œ์ด๋ธ”์—์„œ ์‚ฌ์›๋ช…, ํ•ด๋‹น ์‚ฌ์›์˜ ๊ด€๋ฆฌ์ž๋ช…, ํ•ด๋‹น ์‚ฌ์›์˜ ๊ด€๋ฆฌ์ž์˜ ๊ด€๋ฆฌ์ž๋ช…์„ ๊ฒ€์ƒ‰ํ•˜์‹œ์˜ค

     

     

    SELECT E.ENAME ์‚ฌ์›๋ช…, M.ENAME ๊ด€๋ฆฌ์ž๋ช…, MM.ENAME "๊ด€๋ฆฌ์ž์˜ ๊ด€๋ฆฌ์ž๋ช…"
    FROM EMP E, EMP M, EMP MM
    WHERE E.MGR = M.EMPNO AND M.MGR = MM.EMPNO;

     

     

    8. 7๋ฒˆ ๊ฒฐ๊ณผ์—์„œ ์ƒ์œ„ ๊ด€๋ฆฌ์ž๊ฐ€ ์—†๋Š” ๋ชจ๋“  ์‚ฌ์›์˜ ์ด๋ฆ„๋„ ์‚ฌ์›๋ช…์— ์ถœ๋ ฅ๋˜๋„๋ก ์ˆ˜์ •ํ•˜์‹œ์˜ค.

     

    ๋”๋ณด๊ธฐ

    ํ‹€๋ฆฐ๋‹ต์•ˆ)

    ์™œ OUTER๊ฐ€ EMPNO ์ชฝ์œผ๋กœ ๋ถ™๋Š”์ง€ ์ดํ•ดํ•ด์•ผ ํ•œ๋‹ค.

     

    SELECT E.ENAME ์‚ฌ์›๋ช…, M.ENAME ๊ด€๋ฆฌ์ž๋ช…, MM.ENAME "๊ด€๋ฆฌ์ž์˜ ๊ด€๋ฆฌ์ž๋ช…"
    FROM EMP E, EMP M, EMP MM
    WHERE E.MGR = M.EMPNO(+) AND M.MGR = MM.EMPNO(+);

    ์ด ์‚ฌ์›์˜ ๋งค๋‹ˆ์ € ๊ฐ’์ด NULL ์ด๋‹ˆ๊นŒ M ์„ ์กฐํšŒํ•˜๋Š” ์ปฌ๋Ÿผ์— (+)๋ฅผ ๋ถ™์ธ๋‹ค.

     

     

    9. 20๋ฒˆ ๋ถ€์„œ์˜ ์ด๋ฆ„๊ณผ ๊ทธ ๋ถ€์„œ์— ๊ทผ๋ฌดํ•˜๋Š” ์‚ฌ์›์˜ ์ด๋ฆ„์„ ์ถœ๋ ฅํ•˜์‹œ์˜ค.

     

     

    SELECT DNAME, ENAME
    FROM EMP E, DEPT D
    WHERE E.DEPTNO = D.DEPTNO
    AND D.DEPTNO = 20;

     

     

    10. ์ปค๋ฏธ์…˜์„ ๋ฐ›๋Š” ์‚ฌ์›์˜ ์ด๋ฆ„, ์ปค๋ฏธ์…˜, ๋ถ€์„œ์ด๋ฆ„ ์ถœ๋ ฅํ•˜์‹œ์˜ค.

     

    ์™œ ํ‹€๋ ธ๋‚˜? >> ๊ณตํ†ต์ปฌ๋Ÿผ ๋ช…์‹œ๊ฐ€ ์ž˜๋ชป๋๋‹ค.

     

    ์ •๋‹ต! IS NOT NULL๋„ ์ž˜ ์‚ฌ์šฉํ–ˆ๋‹ค

     

     

    11. ์ด๋ฆ„์— ‘A’ ๊ฐ€ ๋“ค์–ด๊ฐ€๋Š” ์‚ฌ์›๋“ค์˜ ์ด๋ฆ„๊ณผ ๋ถ€์„œ๋ช… ์ถœ๋ ฅํ•˜๊ธฐ.

     

     

     

    12. DALLAS์— ๊ทผ๋ฌดํ•˜๋Š” ์‚ฌ์› ์ค‘ ๊ธ‰์—ฌ 1500 ์ด์ƒ์ธ ์‚ฌ์›์˜ ์ด๋ฆ„, ๊ธ‰์—ฌ, ์ž…์‚ฌ์ผ , ๋ณด๋„ˆ์Šค(comm)์„ ์ถœ๋ ฅํ•˜์‹œ์˜ค.

     

     

     

    13. ์ž์‹ ์˜ ๊ด€๋ฆฌ์ž ๋ณด๋‹ค ์—ฐ๋ด‰(sal)์„ ๋งŽ์ด ๋ฐ›๋Š” ์‚ฌ์›์˜ ์ด๋ฆ„๊ณผ ์—ฐ๋ด‰์„ ์ถœ๋ ฅํ•˜์‹œ์˜ค.

     

    SELECT ENAME, SAL
    FROM EMP E JOIN EMP M ON E.MGR = M.EMPNO
    WHERE E.SAL > M.SAL;
    
    -- ๋•ก!ERRRRRRORRRRR

     

    ์ž์‹ ์˜ ๊ด€๋ฆฌ์ž์˜ ์—ฐ๋ด‰๊ณผ ์ž์‹ ์˜ ์—ฐ๋ด‰์„ ๋น„๊ต

     

    ๋‚ด๊ฐ€ ๋†“์นœ ๋ถ€๋ถ„ >> ์…€ํ”„ ์กฐ์ธํ•œ ์ƒํ™ฉ์—์„œ ๋˜‘๊ฐ™์€ ์ปฌ๋Ÿผ์„ ๊ฐ€์ง„ ํ…Œ์ด๋ธ” 2๊ฐœ๊ฐ€ ์กด์žฌํ•˜๊ธฐ ๋•Œ๋ฌธ์— SELECT์—์„œ๋„ ์ •๋ณด๋ฅผ ๋ฝ‘์•„์˜ฌ ํ…Œ์ด๋ธ”๋ช…์„ ๋ช…์‹œํ•ด ์ฃผ์–ด์•ผ ํ•œ๋‹ค.

     

     

    14. ์ง์› ์ค‘ ํ˜„์žฌ์‹œ๊ฐ„ ๊ธฐ์ค€์œผ๋กœ ๊ทผ๋ฌด ๊ฐœ์›” ์ˆ˜๊ฐ€ 30๋…„(12 * 30๊ฐœ์›”) ๋ณด๋‹ค ๋งŽ์€ ์‚ฌ๋žŒ์˜ ์ด๋ฆ„, ๊ธ‰์—ฌ , ์ž…์‚ฌ์ผ , ๋ถ€์„œ๋ช…์„ ์ถœ๋ ฅํ•˜์‹œ์˜ค

     

    SELECT ENAME, SAL, HIREDATE, DNAME
    FROM EMP E JOIN DEPT D USING(DEPTNO)
    WHERE MONTHS_BETWEEN(SYSDATE, HIREDATE) > 360;

     

    MONTHS_BETWEEN์„ ์‚ฌ์šฉํ•  ๋•Œ S ๋น ๋œจ๋ฆฌ์ง€ ์•Š๊ฒŒ ์ฃผ์˜ํ•  ๊ฒƒ.

     

     

    15. ๊ฐ ๋ถ€์„œ๋ณ„๋กœ 1982๋…„ ์ด์ „์— ์ž…์‚ฌํ•œ ์ง์›๋“ค์˜ ์ธ์›์ˆ˜๋ฅผ ์ถœ๋ ฅํ•˜์‹œ์˜ค.

     

     

    -- ์˜ค๋ผํด ์กฐ์ธ
    
    SELECT DEPTNO ๋ถ€์„œ๋ฒˆํ˜ธ, COUNT(ENAME) ์ธ์›์ˆ˜
    FROM EMP E, DEPT D
    where d.deptno = e.deptno
    and to_char(e.hiredate, 'yyyy') <=1982
    group by d.dname;

     

     

     


     

    ์„œ๋ธŒ์ฟผ๋ฆฌ ์‹ค์Šต๋ฌธ์ œ

     

    1. ์‚ฌ์› ํ…Œ์ด๋ธ”์—์„œ BLAKE ๋ณด๋‹ค ๊ธ‰์—ฌ๊ฐ€ ๋งŽ์€ ์‚ฌ์›๋“ค์˜ ์‚ฌ๋ฒˆ, ์ด๋ฆ„ , ๊ธ‰์—ฌ๋ฅผ ๊ฒ€์ƒ‰ํ•˜์‹œ์˜ค.

    ์‚ฌ์›ํ…Œ์ด๋ธ”์— BLAKE์˜ ๊ธ‰์—ฌ๋ฅผ ๋จผ์ € ์ฐพ๋Š”๋‹ค.

    WHERE ์ ˆ์— ๋น„๊ต์—ฐ์‚ฐ์ž๋ฅผ ์‚ฌ์šฉํ•ด SELECT๋ฌธ์„ ์™„์„ฑํ•œ๋‹ค.

     

     

    2. ์‚ฌ์› ํ…Œ์ด๋ธ”์—์„œ MILLER ๋ณด๋‹ค ๋Šฆ๊ฒŒ ์ž…์‚ฌํ•œ ์‚ฌ์›์˜ ์‚ฌ๋ฒˆ, ์ด๋ฆ„, ์ž…์‚ฌ์ผ์„ ๊ฒ€์ƒ‰ํ•˜์‹œ์˜ค

     

    ๋‚˜์˜ ํ‹€๋ฆฐ ๋ฌธ์žฅ

     

    ๋ฐ€๋Ÿฌ๋ณด๋‹ค ๋Šฆ๊ฒŒ ์ž…์‚ฌํ•œ ๊ฑฐ๋ฉด HIREDATE ์ˆซ์ž๊ฐ€ ๋” ์ปค์•ผ ํ•˜๋‹ˆ๊นŒ ๋ถ€๋“ฑํ˜ธ๋Š” ๋ฐ˜๋Œ€๊ฐ€ ๋˜์–ด์•ผํ•œ๋‹ค.

     

    SELECT EMPNO, ENAME, HIREDATE
    FROM EMP
    WHERE HIREDATE > (SELECT HIREDATE
    FROM EMP
    WHERE ENAME = 'MILLER');

    ์ •๋‹ต!

     

     

    3. ์‚ฌ์› ํ…Œ์ด๋ธ”์—์„œ ์‚ฌ์› ์ „์ฒด ํ‰๊ท  ๊ธ‰์—ฌ๋ณด๋‹ค ๊ธ‰์—ฌ๊ฐ€ ๋งŽ์€ ์‚ฌ์›๋“ค์˜ ์‚ฌ๋ฒˆ, ์ด๋ฆ„ , ๊ธ‰์—ฌ๋ฅผ ๊ฒ€์ƒ‰ํ•˜์‹œ์˜ค.

     

     

     

    4. ์‚ฌ์› ํ…Œ์ด๋ธ”์—์„œ ๋ถ€์„œ๋ณ„ ์ตœ๋Œ€ ๊ธ‰์—ฌ๋ฅผ ๋ฐ›๋Š” ์‚ฌ์›๋“ค์˜ ์‚ฌ๋ฒˆ, ์ด๋ฆ„, ๋ถ€์„œ์ฝ”๋“œ, ๊ธ‰์—ฌ๋ฅผ ๊ฒ€์ƒ‰ํ•˜์‹œ์˜ค.

     

    SELECT EMPNO, ENAME, DEPTNO, SAL
    FROM EMP
    WHERE SAL IN (SELECT MAX(SAL)
    	      FROM EMP
    	      GROUP BY DEPTNO);

    ๋ถ€์„œ๋Š” 4๊ฐœ๊ฐ€ ์žˆ๊ณ  ๊ทธ์ค‘ 40์€ ๋ฐ์ดํ„ฐ๊ฐ’์ด ์—†๋‹ค. ๋”ฐ๋ผ์„œ 3๊ฐœ ๋ถ€์„œ์— ๋Œ€ํ•œ ์ตœ๋Œ€๊ธ‰์—ฌ ์„œ๋ธŒ์ฟผ๋ฆฌ๊ฐ€ ๋ฆฌํ„ด๋œ๋‹ค.

    ๊ทธ๋ฃนํ•จ์ˆ˜๋Š” ๋‹จ์ผํ–‰์„ ๋ฆฌํ„ดํ•œ๋‹ค๊ณ  ํ–ˆ๋Š”๋ฐ, ์™œ ์ €๊ธฐ์— ๋ณต์ˆ˜ํ–‰ ์„œ๋ธŒ์ฟผ๋ฆฌ์˜ ์—ฐ์‚ฐ์ž(IN)๊ฐ€ ๋ถ™์–ด๋„ ๊ฒฐ๊ณผ๊ฐ€ ์ž˜ ๋‚˜์˜ค๋Š”๊ฑฐ์ง€? ํ˜ผ๋ž€์Šค๋Ÿฌ์› ๋Š”๋ฐ, GROUP BY๊ฐ€ ๋ถ™์–ด์„œ ๋ณต์ˆ˜ํ–‰ ๊ฒฐ๊ณผ๊ฐ€ ์ถœ๋ ฅ๋˜๋Š” ์„œ๋ธŒ์ฟผ๋ฆฌ์ž„์„ ํ™•์ธํ–ˆ๋‹ค.

    ๊ทธ๋ž˜์„œ ๋™๋“ฑ์—ฐ์‚ฐ์ž(=)๊ฐ€ ์•„๋‹Œ IN ์—ฐ์‚ฐ์ž๊ฐ€ ์‚ฌ์šฉ๋œ ๊ฒƒ์ด๋‹ค.

     

     

    5. Salgrade๊ฐ€ 2๋“ฑ๊ธ‰์ธ ์‚ฌ์›๋“ค์˜ ํ‰๊ท  ๊ธ‰์—ฌ๋ณด๋‹ค ์ ๊ฒŒ ๋ฐ›๋Š” ์‚ฌ์› ์ •๋ณด๋ฅผ ๊ฒ€์ƒ‰ํ•˜์‹œ์˜ค.

     

    SELECT * FROM EMP E, SALGRADE S
    WHERE SAL < (SELECT AVG(SAL)
    FROM EMP
    WHERE S.GRADE = 2);

    ํ‹€๋ ธ๋‹ค! ์ด ์ฟผ๋ฆฌ๋ฌธ์€ 8๋ช…์˜ ์ •๋ณด๋ฅผ ์ถœ๋ ฅํ•˜๊ฒŒ ๋œ๋‹ค.

    ๋‘ ํ…Œ์ด๋ธ”์€ ๊ณตํ†ต์ปฌ๋Ÿผ์ด ์—†๋Š” ๋…ผ ์ดํ€„ ์กฐ์ธ์ด๋‹ค.

    ๋”ฐ๋ผ์„œ ์„œ๋ธŒ์ฟผ๋ฆฌ WHERE ์ ˆ์—๋„ ๋น„๊ต์—ฐ์‚ฐ์ž๋ฅผ ์จ์ค˜์•ผ ํ•˜๋Š”๋ฐ ์—‰๋šฑํ•œ ์ดํ€„์ด ๋“ค์–ด๊ฐ€์žˆ๋‹ค.

     

    SELECT *
    FROM EMP
    WHERE SAL <= (SELECT AVG(SAL)
    		FROM EMP E JOIN SALGRADE S
    		ON E.SAL BETWEEN S.LOSAL AND S.HISAL
    		WHERE S.GRADE = 2);

    ์ •๋‹ต! ์„œ๋ธŒ์ฟผ๋ฆฌ ์•ˆ์—์„œ ANSI์กฐ์ธ์„ ์‚ฌ์šฉํ•œ ์ด ์ฟผ๋ฆฌ๋ฌธ์€ 5๋ช…์˜ ์ •๋ณด๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค.

     

    ์„œ๋กœ ๊ณตํ†ต์ปฌ๋Ÿผ์ด ์—†๊ธฐ ๋•Œ๋ฌธ์— ๋‚ด๊ฐ€ ์กฐ์ธ์กฐ๊ฑด์„ ๋ช…์‹œํ•˜์ง€ ์•Š์œผ๋ฉด ๊ฒ€์ƒ‰์กฐ๊ฑด์„ ์ €๋ ‡๊ฒŒ ์จ์ค˜๋„ ๋จนํžˆ์ง€ ์•Š๋Š”๋‹ค.

    ๋“ฑ๊ธ‰๋งŒ์œผ๋กœ ์‚ฌ์›์ •๋ณด๋ฅผ ๋ฝ‘์•„๋ดค์„ ๋•Œ ๋ถˆํ•„์š”ํ•œ ๋ชจ๋“  ์ •๋ณด๊ฐ€ ๋ฆฌํ„ด๋˜๋Š” ๊ฑธ ์•Œ ์ˆ˜ ์žˆ๋Š”๋ฐ, ์ด๊ฑด ์กฐ๊ฑด์ ˆ์ด ๋ช…ํ™•ํ•˜์ง€ ์•Š์•˜๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค. ๋…ผ์ดํ€„ ์กฐ๊ฑด์ ˆ์— SAL๋“ฑ๊ธ‰์˜ ๋ฒ”์œ„๋ฅผ  SAL BETWEEN S.LOSAL AND S.HISAL ์ด๋ ‡๊ฒŒ ๋ช…์‹œํ•ด์•ผ ํ•œ๋‹ค.

    ํ‰๊ท ์ƒ์ด ์ƒ๋“ฑ๊ธ‰ ์กฐ๊ฑด์˜ ์–ด๋–ค ๊ฐ’ ์‚ฌ์ด์— ํฌํ•จ๋˜๋Š”์ง€ ํ™•์ธํ•˜๋Š” ๊ฒƒ์ด ๋จผ์ €๊ณ , ๊ทธ ๋‹ค์Œ 2๋“ฑ๊ธ‰์— ํ•ด๋‹น๋˜๋Š” ๊ฐ’์„ ๊ฑธ๋Ÿฌ๋‚ธ๋‹ค.

     

    -- ์˜ค๋ผํด ์กฐ์ธ์œผ๋กœ ์จ๋ณด๊ธฐ
    
    SELECT *
    FROM EMP
    WHERE SAL <= (SELECT AVG(SAL)
    FROM EMP E, SALGRADE S
    WHERE E.SAL BETWEEN S.LOSAL AND S.HISAL
    AND S.GRADE = 2); -- ์ˆœ์„œ๋„ ์ค‘์š”ํ•˜๋‹ค๋Š” ๊ฑธ ์•Œ์•˜๋‹ค

     

     

     

    ๐Ÿ˜œ NEXT : SQL DML ๋ช…๋ น๋ฌธ ์•Œ์•„๋ณด๊ธฐ

    ๋ฐ˜์‘ํ˜•

    ๋Œ“๊ธ€

๊ฐœ๋ฐœ๊ณต๋ถ€