Adding up only highest 7 numbers in a table

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • CD Tom
    Contributor
    • Feb 2009
    • 495

    Adding up only highest 7 numbers in a table

    I have a table that can contain up to 12 entries for an individual in the number field each number can be different number I want only to add up the top 7 numbers for each individual. What's the easiest way to do this.

    Thanks
  • cactusdata
    Recognized Expert New Member
    • Aug 2007
    • 223

    #2
    You will need a unique Id for each record. Then:

    Code:
    Select IndividualId, Value
    From YourTable
    Where Id In
        (Select Top 7 T.Id
        From YourTable As T
        Where T.IndividualId = YourTable.IndividualId
        Order by T.Value Desc, T.Id)

    Comment

    Working...