Access¿ìËÙ¿ª·¢»ù´¡½Ì³Ì
ÍøÕ¾¹«¸æ
¡¤Accessר¼Ò¿ÎÌÃQQȺºÅ£º239158550    ¡¤Access¿ìËÙ¿ª·¢Æ½Ì¨ÏÂÔØµØÖ·¼°½Ì³Ì    ¡¤»¶Ó­¼ÓÈëAccessר¼Ò¿ÎÌÃ΢ÐÅȺ£¡    ¡¤ÈçºÎ¿ìËÙËÑË÷±¾Õ¾ÎÄÕÂ|ʾÀý|×ÊÁÏ    
ÄúµÄλÖ㺡¡Ê×Ò³ > ¼¼ÊõÎÄÕ > AccessÊý¾Ý¿â-²éѯ/SQLÓï¾ä

¡¾ÒëÎÄ¡¿Ñ¡Ôñ×îǰ¼Ç¼µÄ²éѯ

ʱ¡¡¼ä:2012-04-10 11:44:18
×÷¡¡Õß:ÖÜ·¼   ID£º24526  ³ÇÊУºÉϺ£
Õª¡¡Òª:ÓÃÒ»¸ö²éѯ´ÓÒ»¸ö±íÖÐÑ¡Ôñ×îǰNÌõ¼Ç¼¡£
Õý¡¡ÎÄ:

Ô­×÷ÕߣºÎ´Öª¡¡¡¡·­Ò룺ÖÜ·¼

¡¾ÒëÎÄ¡¿Ñ¡ÔñǰNÌõ¼Ç¼µÄÀý×Ó

      ÄãÔø¾­ÓÐÐèÒªÓÃÒ»¸ö²éѯ´ÓÒ»¸ö±íÖÐÖ»»ñȡǰÈýÌõ¼Ç¼µÄ¾­ÀúÂð£¿

      ÄÇô,Èç¹ûÄãÏëÖªµÀÈçºÎÈ¥×ö£¬ÕâÀï¾ÍÓÐÒ»¸öÑ¡Ôñ×îǰ¼Ç¼²éѯµÄ½â¾ö·½°¸£º


1) ´´½¨Ò»¸ö²éѯ(Query1£©À´»ñµÃǰÈýÃûµÄ¼Ç¼£¬ÔÚ¡°M_Revisions¡±±íÖеġ°Submit_Date¡±×Ö¶Î

      Select Top 3 M_Revisions.Submit_Date from M_Revisions order by M_Revisions.Submit_Date
      Ñ¡Ôñǰ3Ìõ¼Ç¼ ´ÓM_Revisions±íÖУ¨°´Submit_DateÉýÐò£©¡£

2) ʹÓÃQuery1×÷ΪÊý¾ÝÔ´Éú³ÉÒ»¸öеIJéѯ

      Select Top 1 Query1.Submit_Date from Query1 order by Query1.Submit_Date DESC
      Ñ¡ÔñµÚ1ÐмǼ£¬ÔÚ²éѯQuery1ÖУ¨°´×Ö¶ÎSubmit_Date½µÐòÅÅÁУ©

      ÏÖÔÚÄã¾ÍµÃµ½Á˵Ú3¸ö¡°Ìá½»ÈÕÆÚ¡±Öµ£¬×¢Ò⣬Õâ¸öеÄQuery1²éѯÈÃÕâÈýÌõ¼Ç¼°´ÕÕ½µÐòÅÅÐòÈ»ºó¾ÍʹµÃµÚÈýÌõ¼Ç¼Åܵ½µÚһλ¡£

      Äã¿ÉÒÔʹÓá°Select Top¡±¼ìË÷ÈκÎÊýÁ¿µÄ¼Ç¼£¬±ÈÈ磺

      Select Top 10 Ñ¡Ôñǰ10ÌõÐÅÏ¢

      Select Top 100 Ñ¡Ôñǰ100ÌõÐÅÏ¢

      Select Top 123 Ñ¡Ôñǰ123ÌõÐÅÏ¢

      ÈçÉÏËùʾ,Äã¿ÉÒÔ·Ö×éºóÓÃÅÅÐòÑ¡Ïî (group by)À´Ñ¡ÔñÊʵ±µÄ×îǰ¼Ç¼¡£ÔÚÄãµÄ²éѯÖУ¬Äã¿ÉÒÔ°ÑÕâ¸ö¸ú±êÁ¿²éѯѡÏîÁªºÏÆðÀ´À´Íê³É¸´ÔӵIJÙ×÷¡££¨×¢£º±êÁ¿²éѯ£¬²éѯ¿ÉÒÔÔÚselect×Ó¾äÖÐÖ¸¶¨ÀàµÄÊôÐÔ¡£ÉõÖÁ¿ÉÒÔµ÷ÓÃSQLµÄͳ¼Æº¯Êý¡££©

      ʹÓÃ"select top"Ñ¡Ôñ×îǰ¼Ç¼²¢·ÇûÓÐÎÊÌâ¡£ÎÒÃÇÒѾ­×¢Òâµ½ÓÐÒ»¸öbug,µ±ÄãÑ¡Ôñ²éѯ20µ½30¸ö×Ö·ûµÄ³¤Îı¾×Ö¶Îʱ£¬»ùÓÚ×î¸ß¼Í¼²éѯµÄһЩÎÊÌ⣬Îı¾Êý¾ÝÒ²ÊÇÒ»ÑùµÄ¡£ÀýÈç,Èç¹ûÄãÑ¡Ôñǰ100¼Ç¼£¬Äã¿ÉÄÜ»áµÃµ½110¼Ç¼¡£

¡¾Ô­ÎÄ¡¿

Select Top Query

Select Top n Records Predicate Example

Have you ever had the need to get the 3rd record from a table using a query only?

Well, in case you want to know how to do it here is the select top records query solution:

1) Create a query (Query1) to get the top three records.  We are interested in field called Submit_Date from a table

Select Top 3 M_Revisions.Submit_Date from M_Revisions order by M_Revisions.Submit_Date;

2) Use Query1 as input to a new query:

Select Top 1 Query1.Submit_Date from Query1 order by Query1.Submit_Date DESC;

Now you have the 3rd submit date.  Note that sorting the Query1 records in descending order makes the 3rd record go to the top.

You can use Select Top query to retrieve any number of records such as:

Select Top 10

Select Top 100

Select Top 123

As shown above you can use the sort option (Group By) to arrange the records in the order you want to select the appropriate top records.  You can combine this with the scalar query option to perform complex operations with your queries.

The select top query is not without its problems.  We have noticed a bug in the select top predicate query when you are selecting from long text fields where the first 20 to 30 characters are the same in the text data.  For instance, if you use Select Top 100 you may get back 110 records.



AccessÈí¼þÍøQQ½»Á÷Ⱥ (ȺºÅ:115180141) ¡¡¡¡¡¡¡¡¡¡¡¡AccessÔ´ÂëÍøµê

³£¼ûÎÊ´ð:

¼¼Êõ·ÖÀà:

Ïà¹Ø×ÊÔ´:

רÀ¸×÷¼Ò

¹ØÓÚÎÒÃÇ | ·þÎñÌõ¿î | ÔÚÏßͶ¸å | ÓÑÇéÁ´½Ó | ÍøÕ¾Í³¼Æ | ÍøÕ¾°ïÖú