To get the latest data record, group them by job_id
and sort them down by user_id
and fetch the first row. All this with the ROW_NUMBER()
function
SELECT job_id,user_id,user_name,search_role
FROM
(SELECT *,
ROW_NUMBER() OVER(PARTITION BY job_id ORDER BY user_id DESC) as seq
FROM table) t
WHERE seq = 1
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.