MS-SQL > Sub Query º¸´Ù´Â Join À» »ç¿ëÇ϶ó µî·ÏÀÏ : 2017-07-03 19:43 Á¶È¸¼ö : 52,447JOINÀ» »ç¿ëÇϵµ·Ï ÇÏÀ§ Äõ¸®¸¦ ´Ù½Ã ÀÛ¼ºÇÏ¿© ¼º´ÉÀ» Çâ»ó½Ãų ¼ö ÀÖ½À´Ï´Ù.
JOINÀ» ¸¸µé¸é Äõ¸®¿¡¼ Á¤ÀÇÇÑ °Í°ú ´Ù¸¥ ¼ø¼·Î Å×À̺íÀ» Æò°¡ÇÒ ¼ö ÀÖ´Ù´Â ÀåÁ¡ÀÌ ÀÖ½À´Ï´Ù. ÇÏÀ§ Äõ¸®¸¦ »ç¿ëÇϸé ÇÏÀ§ Äõ¸® ½ÄÀ» Æò°¡Çϱâ À§ÇØ ÇÏÀ§ Äõ¸®ÀÇ ¸ðµç ÇàÀ» °Ë»öÇÒ ÇÊ¿ä°¡ ¾ø´Ù´Â ÀåÁ¡ÀÌ ÀÖ½À´Ï´Ù. ¿¹¸¦ µé¾î EXISTS ÇÏÀ§ Äõ¸®´Â ù ¹ø° ÇÑÁ¤ ÇàÀ» ¸¸³¯ °æ¿ì TRUE¸¦ ¹ÝȯÇÒ ¼ö ÀÖ½À´Ï´Ù. ¿¹¸¦ µé¾î ÇÒÀÎÀ²ÀÌ 25% ÀÌ»óÀÎ Ç°¸ñÀÌ Çϳª ÀÌ»ó Æ÷ÇÔµÈ ¸ðµç ÁÖ¹®À» È®ÀÎÇÏ·Á´Â °æ¿ì ´ÙÀ½°ú °°Àº EXISTS ÇÏÀ§ Äõ¸®¸¦ »ç¿ëÇÒ ¼ö ÀÖ½À´Ï´Ù. SELECT "Order ID" FROM Orders O WHERE EXISTS (SELECT "Order ID" FROM "Order Details" OD WHERE O."Order ID" = OD."Order ID" AND Discount >= 0.25) JOINÀ» »ç¿ëÇÏ¿© ´ÙÀ½°ú °°ÀÌ ´Ù½Ã ÀÛ¼ºÇÒ ¼ö ÀÖ½À´Ï´Ù. SELECT DISTINCT O."Order ID" FROM Orders O INNER JOIN "Order Details" OD ON O."Order ID" = OD."Order ID" WHERE Discount >= 0.25
|