ACC: ????? ????? ??? ???? N ??? ??????? ????????

?????? ????????? ?????? ?????????
???? ???????: 153747 - ??? ???????? ???? ????? ????? ??? ???????.
??????: ????? ????? ???????? ????? ? ???????? ??????? ??????? ????????.
????? ???? | ?? ????

?? ??? ??????

??????

???? ??? ??????? ??????? ???? ?????????? ?????? ????????? ????? ??????? N ?????? ??? ??? ??????. ???????? ??? ???????? ??????? ????? ????? ??????? ? ??? ???? ??????? ???? ????? ??? ?? ???? ??? ???????? ??? ?????.

??????? ??????? ???????? ?? ??? ?????? ????? ?? ???? ?????? ?? Visual Basic for Applications ?????? ????? ??????? Microsoft Access ??????? ????? ??????? ???????? ?? Microsoft Access. ????? ?? ????????? ??? Visual Basic for Applications ?????? ?????? ??? ??????? ????? ?? ?? ???? "????? ??????? ?? Microsoft Access".

??????? ????

???? ?????? N ??????? ??? ???? ?????? ?? ???????? ??? ???? ????? ?????? ???? ?????? ?????? ??????? ?? ????????? ???? ???? ????? ?????? ???? ???? ??? ????? ?????? N ???? ?? ??????. ??????? ?????? ?????? ??????? ???? SQL ???? ???? ????? ????? ???????? N ?????? ??? ?????? ??????? ?? ??? ??????? ??????? ???? ?????? ???????? ???? ??????? IN. ??????? ??????? ?????? ???? ????? ?? ??? ???????? ?????? ?????? Nth ???? ?????? ????? ?? ??????? ?? > = ???? ??????? ?????? Nth ??????? ????.

??????? ??????

???? ?????? ?????? ????? ????? ??????? ?? ????? ?????? ????? Northwind ???? ???????_??????? ????? ?????? ??? ????_?????. ????????? ?????? ??????? ???? SQL ???? ???? ?????? ???????_??????? ????? ?????? ????? ????_????? ?????, ??? ?? ?????? ???? ??????? IN ?????? ??????? ?? ????????? ???????.

??????: ?? ??????? ???????? ?? ?????? 5 ????? ???? ????? (_) ?? ????? ??? ??? ??????? ??? ?????? ???. ?? ?????? ????? ???? ????? "?? ????? ????? ??? ????? ????? ????????.

  1. ???? ????? ????? ???????? Northwind.mdb.
  2. ???? ??? ????? ??????? ????????? ?? ???? ??? ????.
  3. ???? ??? ????? ????? "?????" ?? ???? ??? ?????.
  4. ?? ???? ?????? "????? ????" ? ??? ?? ?????? ????????? ??????? ?? ???? ??? ?????.
  5. ??? ?????? ??????? ??? ???? ????? ?????????:
    ??? : CategoryName
    ?????: ??????

    ?????: ProductName

    ?????: ???????_???????
    ?????: ??????
    ????????: ?? (????? ???? 3 [UnitsInStock] ?? ???????? Where _
    [????_?????] = [????]. [????_?????] ????? ??? ?????? [UnitsInStock])
  6. ????? ?????????. ???? ?? ????????? ???? ?????? ?????? ???????_??????? ???? ??? ???.

??????? ???????

???? ?????? ?????? ????? ????? ??????? ?? ????? ?????? ????? Northwind ???? ???? ?? ??? ???? ??????? ??? ???????. ????????? ?????? ???? ?????? ???? NthInGroup() ????? OrderDate ???? ?????? ????? ????? ???? ?????? ?????. ???????? > = ???? ??????? ?? ??? ?????? ???? ?????? ???? ??????? ???? ?? ????? ?? ?? ??? OrderDate ???? ?????? ??? ????:

  1. ???? ????? ????? ???????? Northwind.mdb.
  2. ????? ???? ????? ????? ?? ?? ?????? ????? ?????? Declarations ?????? ??? ?? ??? ????:
    ?????? Explicit
  3. ????? ??????? ??????:
          Function NthInGroup(GroupID, N)
          ' Returns the Nth Item in GroupID for use as a Top N per group
          ' query criteria.
          Static LastGroupId, LastNthInGroup
          Dim ItemName, GroupIDName, GDC, SearchTable
          Dim SQL As String, rs As Recordset, db As DATABASE
    
          If (LastGroupId = GroupID) Then
             ' Returned saved result if function is called with the
             ' same GroupID more than once in a row.
             NthInGroup = LastNthInGroup
          Else
             ' Set the SQL statement parameters. These are the only items
             ' that need to be customized in this function.
             ' Set to Item field name.
             ItemName = "OrderDate"
             ' Set to Group ID field name.
             GroupIDName = "CustomerID"
             ' GroupID Delimiter Character:
             ' For Text use "'" (Note that this is a quotation mark, a space,
             ' an apostrophe, a space, and then a quotation mark. The spaces
             ' are necessary for SQL statements), Date "#", Numeric ""
             GDC = "'"
             ' Set to search table.
             SearchTable = "Orders"
             ' Build a Top N SQL statement dynamically given N and
             ' GroupID as parameters. Note that the sort is by the
             ' item in descending order, in order to get the Top N
             ' largest items.
             SQL = "Select Top " & N & " [" & ItemName & "] "
             SQL = SQL & "From [" & SearchTable & "] "
             SQL = SQL & "Where [" & GroupIDName & "]=" & GDC & GroupID & GDC _
                & " "
             SQL = SQL & "Order By [" & ItemName & "] Desc"
             ' Open up recordset on Top N SQL statement and read the
             ' last record to get the smallest item in the Top N.
             Set db = CurrentDb()
             Set rs = db.OpenRecordset(SQL)
             If (rs.BOF And rs.EOF) Then
                ' No matches found, return a null.
                LastNthInGroup = Null
                LastGroupId = GroupID
                NthInGroup = LastNthInGroup
                Else
                   ' Return the smallest Top N item in the group.
                   rs.MoveLast
                   LastNthInGroup = rs(ItemName)
                   LastGroupId = GroupID
                   NthInGroup = LastNthInGroup
                 End If
              End If
    
           End Function
    						
  4. ????? ?? ?????? ??????? ??? ?? ????? ?? ?? ???? ?????? ??????? ?? basTopN.
  5. ???? ??? ????? ??????? ????????? ?? ???? ??? ????.
  6. ???? ??? ????? ????? "?????" ?? ???? ??? ?????.
  7. ?? ???? ?????? "????? ????" ? ??? ??? ??????? "?" ????? ???????. ???? ??? ?????.
  8. ??? ?????? ??????? ??? ???? ????? ?????????:
    ??? : ???? ??????
    ?????: ??????


    ?????: OrderID

    ?????: ????? ?????
    ?????: ??????
    ????????: > = NthInGroup([Customers].[CustomerID],5)
  9. ????? ?????????. ???? ?? ???? ??????? ????? ????? ??????? ?????? ????? ???? ????????? ?????? ??????? ???? ????. ??????? ??????? ?? ??????? ??? ?? ???? ????????? ?????? ???? ???????.

?????

????? ?? ????????? ??? ????????? ????? ????? ?? ??????????? ??????? ?? ??????????? ??????? SQL ???????? ???? ????????? ????? ?? Microsoft Access 97.

???????

???? ???????: 153747 - ????? ??? ??????: 29/?? ?????/1427 - ??????: 3.3
????? ???
  • Microsoft Access 95 Standard Edition
  • Microsoft Access 97 Standard Edition
????? ??????: 
kbmt kbhowto kbprogramming KB153747 KbMtar
????? ????
???: ??? ????? ??? ?????? ???????? ?????? ????? ???? ????? ?????????? ????? ?? ????????? ?????? ????. ???? ???? ?????????? ???? ?? ???????? ???????? ?????? ????????? ????? ????????? ???????? ????? ???????? ?????? ?? ?????? ??? ?? ???????? ???????? ?? ????? ??????? ?????? ??? ??????? ?????? ??. ?????? ?? ???? ??? ??????? ???????? ????? ?? ???? ????? ?????? ??? ????? ??? ????? ??????? ?? ????? ?? ?????? ??? ??? ??????? ??????? ?? ????? ????? ????? ????? ?????. ?? ????? ???? ?????????? ??????? ??? ????? ?? ??????? ?? ????? ?????? ?? ??? ????? ?? ????? ??????? ?? ???????? ?? ??? ???????. ???? ???? ?????????? ???????? ??? ????? ?????? ??????? ??????
???? ??? ????? ??????? ?????? ??????????153747
????? ??????? ?? ????? ???? ?? ????? ???????
?? ????? ????? ?????? ???? ???? ???? ??? ??????? ??? ?? ? ?? ??? ??????? Microsoft ??? ????? ??? ??????? ????? ?????? ?????

????? ???????

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com