获取表中每个类型最新一条记录【Postgresql】
每条数据的编号:row_number()
分组排序:over (partition by 分组的字段 order by 排序的字段)
num=1:对分组后的数据获取第一条,也就是最新一条
SELECT * FROM (SELECT ROW_NUMBER() over(PARTITION BY id ORDER BY time DESC ) AS num, * FROM monitordata where time>'2023-04-25 9:00:00') a WHERE 1 = 1
AND a.num = 1 ORDER BY a.time DESC;