Query to Return Top Items for Each Distinct Column Value

前端 未结 3 1312
闹比i
闹比i 2021-01-25 09:07

If I have a table with the following fields

ID, SomeFK, SomeTime

How would I write a query return the latest/top 3 items (based on SomeTi

3条回答
  •  星月不相逢
    2021-01-25 09:56

    I think I understood you correctly, can you not select the max SomeTime and then group, like this:

    select SomeFK, max(SomeTime) 
    from Table
    group by SomeFK
    

    I could be off the mark here, as I'm not entirely sure what you mean by latest.

提交回复
热议问题