Standard sql:
select key, value, asof
from (
select *, row_number() over (partition by key order by asof desc) as rn
from <table>
) t
where rn = 1
postgresql: select distinct on (key)
key, value, asof
from <table>
order by key, asof desc
The DISTINCT ON clause takes the first row that the query returns, which the ORDER BY makes sure is the latest valueDisclaimer: I've used both methods, but haven't tested the perf against each other or the self-join.