|
|
|
|
|
0 |
|
View Articles |
|
|
Name |
¼Õº´¸ñ |
(2002-04-14 23:43:15, Hit : 16032, Vote : 1617)
|
|
|
Homepage |
http://www.itmembers.net |
|
Subject |
¿À¶óŬ µ¥ÀÌÅÍ °Ë»ö - SUBSELECT(3) EXIST èâ |
|
|
SUBSELECT ¸¶Áö¸· ½Ã°£ÀÔ´Ï´Ù.
SUBSELECTÀÇ °á°ú °ªÀÌ Çϳª¶óµµ ÀÖÀ¸¸é ½ÇÇàµÇ´Â EXIST¿¡ °üÇÑ ¿ë·Ê¸¦ »ìÆ캸°í,
SUBSELECT¹®À» FROM Àý°ú HAVING Àý¿¡¼ »ç¿ëÇÒ ¶§ÀÇ Æ¯Â¡¿¡ ´ëÇؼµµ ¾Ë¾Æº¸°Ú½À´Ï´Ù.
- EXIST
WHERE Àý¿¡¼ EXIST¸¦ »ç¿ëÇϸé,
SUBSELECT ¹®ÀÇ °á°ú°¡ TrueÀ̸é SELECT ¹®À» ¼öÇàÇÏ°í ±×·¸Áö ¾ÊÀ¸¸é ¼öÇàÇÏÁö ¾Ê½À´Ï´Ù.
SELECT EMP_NUM, LAST_NAME, FIRST_NAME, JOB_CODE
FROM EMP
WHERE EXISTS
( SELECT *
FROM EMP_SKILL
WHERE AVAILABLE = 'YES');
EMP_SKILL Å×ÀÌºí¿¡¼ AVAILABLEÀÇ °ªÀÌ 'YES'ÀÎ ·¹Äڵ尡 Á¸ÀçÇϸé, EMP Å×À̺íÀÇ EMP_NUM, LAST_NAME, FIRST_NAME, JOB_CODE¸¦ Ç¥½ÃÇ϶ó´Â ¶æÀÔ´Ï´Ù.
FROM Àý¿¡¼ SUBSELECT »ç¿ëÇϱâ
SUBSELECT ¹®Àº WHERE Àý »Ó¸¸ ¾Æ´Ï¶ó FROM Àý¿¡¼µµ »ç¿ëÇÒ ¼ö ÀÖ½À´Ï´Ù.
WHERE Àý¿¡¼ »ç¿ëÇÏ´Â °Í°ú °á°ú´Â µ¿ÀÏÇÏÁö¸¸
TABLE¿¡ µ¥ÀÌÅÍ°¡ ¸¹À» ¶§ »ç¿ëÇϸé È¿°úÀûÀÔ´Ï´Ù.
±× ÀÌÀ¯´Â, FROM Àý¿¡¼ SUBSELECT´Â VIEW¿Í °°Àº ¿ªÇÒÀ» Çϱ⠶§¹®ÀÔ´Ï´Ù.(VIEW¿¡ ´ëÇؼ´Â ¸î °Á ÈÄ¿¡ ´Ù·ê ¿¹Á¤ÀÔ´Ï´Ù.)
SELECT EMP_NUM, SKILL_NAME
FROM ( SELECT EMP_NUM, SKILL_NAME, AVAILABLE
FROM SKILL A, EMP_SKILL B
WHERE A.SKILL_NO = B.SKILL_NO)
WHERE AVAILABLE = 'YES';
HAVING Àý¿¡¼ SUBSELECT »ç¿ëÇϱâ
¾Õ¼ ¹è¿î ÀûÀÌ ÀÖÁö¿ä? HAVING ÀýÀº GROUPÀ» ¸¸µå´Â Á¶°ÇÀ» ÁöÁ¤ÇÒ ¶§ »ç¿ëÇÕ´Ï´Ù.(Á¦28° ¿À¶óŬ µ¥ÀÌÅÍ °Ë»ö - ORDER BY, GROUP BY¸¦ º¸¼¼¿ä.)
»ç¿ë¹ýÀº WHERE Àý¿¡¼ »ç¿ëÇÒ ¶§¿Í °°½À´Ï´Ù.
SELECT DEPT_NO, AVG(AMOUNT)
FROM DEPT_SALES
WHERE AMOUNT > 100
GROUP BY DEPT_NO
HAVING AVG(AMOUNT) >
( SELECT AVG(AMOUNT)
FROM DEPT_SALES);
ÀÏ¿äÀÏÀÌ ¸î ½Ã°£ ³²Áö ¾Ê¾Ò³×¿ä.
ÀÌ»ó µ¿ÁÖ ¾Æºü ¼Õº´¸ñÀ̾ú½À´Ï´Ù.
|
|
|
|
|
|