Select Most Recent States From History Table

后端 未结 5 860
栀梦
栀梦 2021-02-08 13:27

I have inherited a table with a structure something like this:

ID   Name   Timestamp   Data
----------------------------
1    A      40          ...
2    A               


        
5条回答
  •  长发绾君心
    2021-02-08 14:17

    Assuming there are no duplicate timestamps per name, something like this should work:

    SELECT ID, Name, Timestamp, Data
    FROM test AS o
    WHERE o.Timestamp = (SELECT MAX(Timestamp)
                         FROM test as i
                         WHERE i.name = o.name)
    

提交回复
热议问题