Create a SQL query to retrieve most recent records

前端 未结 4 2166
暗喜
暗喜 2020-11-29 20:46

I am creating a status board module for my project team. The status board allows the user to to set their status as in or out and they can also provide a note. I was plannin

4条回答
  •  误落风尘
    2020-11-29 21:34

    Aggregate in a subquery derived table and then join to it.

     Select Date, User, Status, Notes 
        from [SOMETABLE]
        inner join 
        (
            Select max(Date) as LatestDate, [User]
            from [SOMETABLE]
            Group by User
        ) SubMax 
        on [SOMETABLE].Date = SubMax.LatestDate
        and [SOMETABLE].User = SubMax.User 
    

提交回复
热议问题