Date: Tue, 26 Jul 2005 19:30:52 +0900
From: "Kohichiroh Ohta" <who@example.co.jp>
¤¤¤Ä¤â¤ªÀ¤ÏäˤʤäƤª¤ê¤Þ¤¹¡£
ËÙÀîÍͤ´²óÅú¤¢¤ê¤¬¤È¤¦¤´¤¶¤¤¤Þ¤·¤¿¡£
> SQL Server 2000¤ËÉÕ°¤¹¤ë¥¯¥¨¥ê¥¢¥Ê¥é¥¤¥¶¤Ç¡¢¥¯¥¨¥ê¤Î¼Â¹Ô¥×¥é¥ó¤Î
> ɽ¼¨µ¡Ç½¤ò»È¤Ã¤Æ¡¢¥¤¥ó¥Ç¥Ã¥¯¥¹¤Î»È¤ï¤ìÊý¤Ê¤É¤òʬÀϤ¹¤ë¤³¤È¤¬¤Ç¤¤Þ¤¹¡£
¤³¤ì¤Ï¤¹¤´¤¤µ¡Ç½¤Ç¤¹¤Í¡¢½é¤á¤Æ¸«¤Þ¤·¤¿¡£
¤Á¤Ê¤ß¤Ë±©À¸ÍͤÎSQL
> SELECT *
> FROM È÷¹Í
> WHERE (È÷¹Í.È÷¹ÍID) In (
> select top 1 È÷¹ÍID
> FROM È÷¹Í as TBL_A
> where È÷¹Í.ÆÀ°ÕÀèID=tbl_A.ÆÀ°ÕÀèID
> order by tbl_a.ÆüÉÕ desc,tbl_a.È÷¹ÍID desc
> )
> ORDER BY È÷¹Í.ÆÀ°ÕÀèID;
¤òʬÀϤ·¤Þ¤¹¤È
¡¡Ö¼ç¥¡¼¡×¤Ë 25%
¢¡ÖTOP 1, ORDER BY TBL_A.ÆüÉÕ DESC, TBL_A.È÷¹ÍID DESC¡× ¤Ë44%
£ ºÆ¤Ó¡Ö¼ç¥¡¼¡×¤Ë 24%
¤ ºÇ¸å¤Ë¡ÖÆÀ°ÕÀèID¤Î¥½¡¼¥È¡×¤Ë 7%
¤È½Ð¤Þ¤·¤¿¡£
¢¤Î½èÍý¤ËÉéô¤¬¤«¤«¤Ã¤Æ¤¤¤ë¤è¤¦¤Ç¤¹¡£
¡Ö¼ç¥¡¼¡×¤¬2²ó½Ð¤Æ¤¤Æ¤¤¤ë¤Î¤â¾¯¤·µ¤¤Ë¤Ê¤ê¤Þ¤¹¡£
³¤±¤ÆËÙÀîÍͤÎSQL
> SELECT * FROM È÷¹Í
> INNER JOIN (
> SELECT ÆÀ°ÕÀèID , MAX(ÆüÉÕ) AS MAXÆüÉÕ
> FROM È÷¹Í GROUP BY ÆÀ°ÕÀèID
> ) È÷¹ÍMAX
> ON È÷¹Í.ÆÀ°ÕÀèID=È÷¹ÍMAX.ÆÀ°ÕÀèID
> AND È÷¹Í.ÆüÉÕ = È÷¹ÍMAX.MAXÆüÉÕ
> ORDER BY È÷¹Í.ÆÀ°ÕÀèID
¤òʬÀϤ·¤Æ¤ß¤Þ¤¹¤È
¡¡Ö¼ç¥¡¼¡×¤Ë 62%
¢¡ÖORDER BY ÆÀ°ÕÀèID DESC, ÆüÉÕ DESC¡× ¤Ë19%
¤ ºÇ¸å¤Ë¡ÖÆÀ°ÕÀèID¤Î¥½¡¼¥È¡×¤Ë 19%
¤È½Ð¤Þ¤·¤¿¡£
ºÇ¤â½èÍý¤¬Â®¤¤¤È¸À¤ï¤ì¤ë¡Ö¼ç¥¡¼¡×¤Ë
¥³¥¹¥È¤¬¤«¤¿¤è¤Ã¤Æ¤¤¤ë¤è¤¦¤Ç¤¹¡£
¤³¤ì¤Ï¥Ñ¥Õ¥©¡¼¥Þ¥ó¥¹¤¬Îɤ¤
¤Èɾ²Á¤·¤Æ¤â¤è¤µ¤½¤¦¤Ç¤¹¡£
·ë¶É¡¢¥Ç¡¼¥¿¤ÎÎ̤¬Áý¤¨¤Æ¤¯¤ë¤È
±©À¸ÍͤÎSQL¤Ç¤¹¤È
¤«¤Ê¤ê½Å¤¯¤Ê¤Ã¤Æ¤·¤Þ¤¦²ÄǽÀ¤¬¤¢¤ë
¤È»ä¤Ïͽ¬¤·¤Þ¤¹¤¬¤É¤¦¤Ç¤·¤ç¤¦¤«¡©
±©À¸Íͼ«¿È¤â
> ¥Ñ¥Õ¥©¡¼¥Þ¥ó¥¹Åª¤Ë¤É¤¦¤Ê¤Î¤«¤âÄ´¤Ù¤¿¤³¤È¤Ï¤¢¤ê¤Þ¤»¤ó¡£
> ¤¿¤À¡¢ÊØÍø¤Ê¤Î¤Ç»þ¡¹»È¤Ã¤Æ¤¤¤Þ¤¹¡£
¤È¤ª¤Ã¤·¤ã¤Ã¤Æ¤¤¤Þ¤¹¤Î¤Ç
°ì±þƳ¤½Ð¤¹ÊýË¡¤Ï¤¢¤ë
¤¬¼ÂºÝ¤Ë¤½¤ì¤ò¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Ë
¼ÂÁõ¤¹¤ë¤«¤Ï¤É¤¦¤«¤ÏÊ̤Ȥ¤¤¦¤³¤È¤Ç¤¹¤Í
ËÙÀîÍͤâ
> ¤¿¤À¡¢¼Â̳¾å¤Ï¡¢Îó¤Ë¥¤¥ó¥Ç¥Ã¥¯¥¹¤ò¿¶¤ê¤Þ¤¹¤Î¤Ç¡¢¤½¤ì¤é¤¬Í¸ú¤Ë
> µ¡Ç½¤¹¤ë¤«¤É¤¦¤«¸¡¾Ú¤·¡¢¥ì¥³¡¼¥ÉÁªÂò½èÍý¤¬Á᤯½ª¤ï¤ë¤â¤Î¤ò
> Àµ²ò¤È¤·¤Þ¤¹¡£
> ¤·¤«¤·¥Æ¡¼¥Ö¥ë¤Ë³ÊǼ¤µ¤ì¤ë¥ì¥³¡¼¥É¿ô¤¬Â¿¤¯¤Ê¤ë¤È¡¢ºÇ½é¤ÏÀµ²ò
> ¤À¤Ã¤¿¤â¤Î¤¬¡¢¤¦¤Þ¤¯»È¤¨¤º¡¢Ê̤ÎÀµ²ò¤òõ¤¹¤³¤È¤â¤¢¤ê¤Þ¤¹¡£
¤È¤ª¤Ã¤·¤ã¤Ã¤Æ¤¤¤Þ¤¹¤Î¤Ç
¥Ç¡¼¥¿Î̤˹ç¤ï¤»¤Æ¸¡Æ¤¤·¤Ê¤±¤ì¤Ð
¤Ê¤é¤Ê¤¤¤È³Ð¤¨¤Æ¤ª¤¤Þ¤¹¡£
¤¿¤Àɽ¸½¤ÎÉý¤Ï¹¤²¤Æ¤ª¤¤¤Æ¤â¤è¤µ¤½¤¦¤Ç¤¹¤Î¤Ç
¤½¤Î°ÕÌ£¤Ç¤ÏÂçÊÑ»²¹Í¤Ë¤Ê¤ê¤Þ¤·¤¿¡£
¤¢¤ê¤¬¤È¤¦¤´¤¶¤¤¤Þ¤·¤¿¡£
[MSDE/SQLServer¤Ë´Ø¤·¤Æ¡¢º£¡¢¤É¤ó¤Ê¤³¤È¤Ë¤ªº¤¤ê¤Ç¤¹¤«¡©] |
¤è¤í¤·¤±¤ì¤Ð¤ªº¤¤ê¤ÎÆâÍƤò¡¢ÅŻҥ᡼¥ë¤Ç¶µ¤¨¤Æ²¼¤µ¤¤¡£ |
¼ÁÌä¤òÅŻҥ᡼¥ë¤ÇºîÀ®¤¹¤ë
|
[¥¦¥£¥ó¥É¤òÊĤ¸¤ë][MSDE/SQLServer FAQ ][MSDE / MSDE2000 µ»½Ñ¥µ¥Ý¡¼¥È¾ðÊó°ìÍ÷]
|