WITH
cte AS (
SELECT *, ROW_NUMBER() OVER (PARTITION BY document_id ORDER BY job_id DESC) rn
FROM my_table
)
SELECT document_id, job_id, person_id
FROM cte
WHERE rn = 1;
SELECT DISTINCT
document_id,
MAX(job_id) OVER (PARTITION BY document_id) job_id,
FIRST_VALUE(person_id) OVER (PARTITION BY document_id ORDER BY job_id DESC) person_id
FROM my_table