Selecting Top N Per Group in PostgreSQL
SELECT
rank_filter.id
FROM
(
SELECT
wxrt_device_record_latest.*, RANK () OVER (
PARTITION BY device_id
ORDER BY
captured_at DESC
)
FROM
wxrt_device_record_latest
) rank_filter
WHERE
RANK < 50
ORDER BY
device_id,
RANK DES.
原创
2021-04-08 10:48:49 ·
73 阅读 ·
0 评论