Access SQL query: find the row with the most recent date for each distinct entry in a table

后端 未结 5 1934
盖世英雄少女心
盖世英雄少女心 2021-02-06 08:50

All,

I\'m sure this is a pretty simple SQL query question, but I\'m sure there\'s a good way, and a very BAD way, to do this. Left to my own devices, I\'m liable to end

5条回答
  •  感动是毒
    2021-02-06 09:21

    If you need both the date and the value, you need to do a join:

    SELECT ID, Value,As_of 
    from yourTable a inner join 
              (SELECT ID, MAX(As_of) as As_of 
              from yourTable group by ID) b 
    on a.ID=b.ID and a.As_of = b.As_of
    

提交回复
热议问题