每条数据的编号: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;
标签:Postgresql,over,表中,获取,num,分组,time,SELECT
From: https://www.cnblogs.com/ikai/p/17351642.html