postgresql - How to select all tuples determined id and newest timestamp -
given table:
id | timestmap | ..otherstuff..
with primary key (id,timestmap). id of type integer , timestamp timestamp.
how can extract tupes of timestamp newest tuple?
e.g. if current data:
1 | 1999-05-23 0:00 | ... 2 | 2000-05-23 0:00 | ... 1 | 2000-06-22 0:00 | ...
i want result (though order bonus not care for)
1 | 2000-06-22 0:00 | ... 2 | 2000-05-23 0:00 | ...
for cases use window functions.
as example assuming table called foo, query work:
with tmp ( select id, timestmap, rank() on (partition id order timestmap desc) foo ) select id, timestmap tmp rank=1;
Comments
Post a Comment