Select Most Recent States From History Table

后端 未结 5 854
栀梦
栀梦 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:06

    SQL Server 2000:

    SELECT
      ID, Name, Timestamp, Data
    FROM
      DataTable
      INNER JOIN
      (
         SELECT ID, MAX(Timestamp) Timestamp FROM DataTable GROUP BY ID
      ) latest ON 
        DataTable.ID = Latest.ID AND 
        DataTable.Timestamp = Latest.Timestamp
    

提交回复
热议问题