Featured image of post mysql 找每一個人的最後一筆紀錄

mysql 找每一個人的最後一筆紀錄

;WITH ls AS (
	SELECT a.*,  b.* 
	FROM public.tables as a LEFT JOIN tables_log as b on a.id = b.id
)

SELECT * FROM (
	SELECT *,
		ROW_NUMBER() OVER (PARTITION BY id ORDER BY time DESC) AS r
	FROM ls
) sub
WHERE r = 1