我的数据库中有一个表,其中插入了行而没有更新旧行。这会导致记录具有相同的 ID 但不同的时间戳。如何编写使用窗口函数读取具有不同 ID 和最新时间戳的行的 SQL 查询?
with base as ( select *, row_number() over(partition by id order by timestamp desc) as rn from table ) select * except(rn) from base where rn = 1