MS-SQL > SubQuery - Áߺ¹ µ¥ÀÌŸ °Ë»ç ¹× »èÁ¦ ¹æ¹ý µî·ÏÀÏ : 2017-07-03 19:11 Á¶È¸¼ö : 52,699¾È³çÇϼ¼¿ä!
±×µ¿¾È °Ç°ÇϼÌÁö¿©? ¿À´Ã ¿©·¯ºÐµéÀÌ º¸½Ã°Ô µÉ Äõ¸®´Â Áߺ¹µ¥ÀÌŸ »èÁ¦ ¹æ¹ý ÀÔ´Ï´Ù. ¾ÆÁÖ À¯¿ëÇÏ°Ô »ç¿ëµÉ¼ö ÀÖ½À´Ï´Ù. ¿¹¸¦ µé¾î member ¶ó´Â Å×ÀÌºí¿¡ board_idx(À妽º) °ª°ú email À̶ó´Â Çʵ带 °¡Áö°í ÀÖ½À´Ï´Ù. ¿©·¯ºÐÀÌ ¸¸¾à ȸ¿øÁß¿¡ email ÀÌ Áߺ¹µÉ¼ö ÀÖ´Ù´Â »ý°¢¿¡ emailÀ» Áߺ¹ÀÌ ÀÖ´ÂÁö ¾ø´ÂÁö °Ë»ç¸¦ ÇØ º¸°í ½Í½À´Ï´Ù. ¾î¶² Äõ¸®¸¦ ³¯¸®¸é µÉ±î¿ä? select count(email),email from member group by email À§¿Í °°Àº Äõ¸®¸¦ ³¯¸®¸é µË´Ï´Ù. email ¸¦ group by ¸¦ ÇÑ´ÙÀ½, count(email) Çϸé,,, email °ú Áߺ¹µÈ email °¹¼ö°¡ ³ª¿À°ÚÁö¿ä? ±×·¸´Ù¸é ¿©±â¿¡¼ Áߺ¹µÈ µ¥ÀÌŸ¸¸ »èÁ¦ÇÏ°í ½Í´Ù¸é ¾î¶»°Ô ÇÏ¸é µÉ±î¿ä? ±×·³ Äõ¸®¸¦ º¸µµ·Ï ÇÏ°Ú½À´Ï´Ù. delete member where board_idx not in (select min(b.board_idx) from member B group by b.email) À§¿Í °°Àº Äõ¸®¸¦ ³¯¸®¸é µÈ´ä´Ï´Ù. ÀÏ´Ü (select min(b.board_idx) from member B group by b.email) ÀÌ Äõ¸®´Â email ¸¦ group by ·Î ¹Àº ´ÙÀ½¿¡ °¡Àå ÀÛÀº board_idx °ªÀ» ±¸ÇÏ°Ô µË´Ï´Ù. ±×·¸´Ù¸é Áߺ¹µÈ µ¥ÀÌŸÀÏ °æ¿ì °¡Àå ÀÛÀº board_idx °ª¸¸ Ãâ·ÂÀ» ÇÏ°ÚÁö¿ä? ¿©±â±îÁö ÀÌÇØ °¡½Ã³ª¿ä?? ¸Â½À´Ï´Ù. Áï, À§ Äõ¸®¸¦ ³¯·Á¼ ³ª¿Â °á°ú°ª board_idx ¿¡ Æ÷ÇÔÀÌ µÇÁö ¾ÊÀº µ¥ÀÌŸ¸¦ ¸ðµÎ »èÁ¦ÇÑ´Ù¸é??? ±×°Ô ¹Ù·Î Áߺ¹µÈ ³ª¸ÓÁö µ¥ÀÌŸ °ÚÁö¿ä?? ±×·¸°æ¿ì, board_idx not in Á¶°Ç¹®À» ½áÁÖ¸é µË´Ï´Ù. Áï, Æ÷ÇÔµÇÁö ¾Ê´Â board_idx °ªÀÌ µÇÁö¿ä? Á¦°¡ °£´ÜÇÏ°Ô ¼³¸íµå·È´Âµ¥, ¾î¶°½ÅÁö¿ä??? ¼³¸íÀÌ ¾î·ÆÁø ¾Ê¾Ò³ª ¸ð¸£°Ú³×¿ä.. ½ÇÁ¦·Î Å×½ºÆ®¸¦ ÇØ º¸½Ã±â ¹Ù¶ø´Ï´Ù. ´ÙÀ½¿£ Á»´õ ½Ç¹«ÀûÀ̱¸, ÇÊ¿äÇÑ ±â´ÉÀ» ã¾Æ¼ ´Ù½Ã ã¾Æ ºËµµ·Ï ÇÏ°Ú½À´Ï´Ù. ±×¶§±îÁö °Ç°ÇϽñæ....
|