Top n records per group sql in access

前端 未结 2 488
耶瑟儿~
耶瑟儿~ 2020-11-28 15:20

I am making some software that tracks the scores of a test. There are multiple users, the details of which are stored in a user table. There is then a progress table which t

2条回答
  •  抹茶落季
    2020-11-28 16:08

    I had a similar problem a year ago: Top 3 per group including 0

    Using the same approach, this will return the latest three dates for each LoginID - you may get more than three records if there are tied dates for the same LoginID.

    SELECT  PR1.LogInID, PR1.Score, PR1.[Date Taken]
    FROM    Progress AS PR1
    WHERE   PR1.[Date Taken] IN (
                            SELECT TOP 3 PR2.[Date Taken]
                            FROM    Progress PR2
                            WHERE   PR2.LoginID = PR1.LoginID
                            ORDER BY PR2.[Date Taken] DESC
                            )
    ORDER BY    LoginID, [Date Taken]
    

提交回复
热议问题