Results 1 to 5 of 5
  1. #1
    zachariack is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2019
    Posts
    6

    Sum of first 5

    Hi friends,



    How to make a query for adding first 5 record for each id as shown in the picture below

    Click image for larger version. 

Name:	Screenshot 2024-01-20 194018.png 
Views:	27 
Size:	7.8 KB 
ID:	51350





  2. #2
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    Join Date
    Apr 2017
    Posts
    1,679
    You question can be paraphrased as 'How to make a query for getting the sum of any random 5 records for each id'. To decide which records from all of records with same ID value must be summarized, you need some additional column to decide which ones to summarize. The reason is, that in Access, there is no way to say a record is before or after of any other, without having a field which determines this order.

  4. #4
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,566
    Can you upload a copy of your database?
    You can PM me if you need further help.
    Good Reading https://docs.microsoft.com/en-gb/off...on-description

  5. #5
    madpiet is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Feb 2023
    Posts
    154
    I think this is what you're looking for: Microsoft Access tips: Subquery basics (allenbrowne.com)
    See "Top N Records per Group"

    In T-SQL you can do it the easy way using CROSS APPLY... yeah, but this isn't T-SQL.

    Oh, this is a HASSLE. You need a "uniquifier" so that the data engine can choose ONE of the tied records. (If you just query for SELECT TOP 1 ... and you just order by Mark, any records with the same mark value will be lumped together! One of the things I really like about the ROW_NUMBER() function in T-SQL!!!)
    Last edited by madpiet; 01-25-2024 at 06:22 PM.

Please reply to this thread with any new information or opinions.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums