Proposal lainnya benar tetapi solusi paling ringkas dan tercepat kemungkinan besar terjadi ketika Anda menggunakan FIRST_VALUE dan LAST_VALUE Fungsi Analitik
SELECT DISTINCT
FIRST_VALUE(LOCATION_ID) OVER (PARTITION BY PERSON_ID ORDER BY THE_DATE
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS LOCATION_ID,
PERSON_ID,
MAX(THE_DATE) OVER (PARTITION BY PERSON_ID) AS LAST_DATE
FROM YOUR_TABLE;
Orang lain lebih suka
SELECT
MAX(LOCATION_ID) KEEP (DENSE_RANK FIRST ORDER BY DATE) as LOCATION,
PERSON_ID,
MAX(DATE) as LAST_DATE
FROM YOUR_TABLE
GROUP BY PERSON_ID;
yang melakukan hal yang sama, tetapi saya tidak begitu akrab dengan klausa ini. Lihat agregate_function KEEP