Ini adalah aplikasi langsung dari metode Tabibitosan untuk menemukan himpunan baris "berturut-turut" dalam barisan. Perbedaan dua analitik row_number()
function membuat flag pengelompokan tambahan yang diperlukan sebelum kita menerapkan agregasi standar.
select employee, job, min(start_date) as start_date, max(end_date) as end_date, FTE
from ( select employee, job, start_date, end_date, FTE,
row_number() over (partition by employee, job order by start_date) -
row_number() over (partition by employee, job, FTE order by start_date)
as grp
from t
)
group by employee, job, FTE, grp
order by employee, start_date
;
EMPLOYEE JOB START_DATE END_DATE FTE
---------- ----- ----------- ----------- ----------
1111 1 19-May-2008 27-Nov-2013 100
1111 1 28-Nov-2013 24-Aug-2015 60
1111 1 25-Aug-2015 11-Sep-2016 68.571
1111 1 12-Sep-2016 29-Sep-2016 72.857
1111 1 30-Sep-2016 10-Nov-2016 91.429
1111 1 11-Nov-2016 23-Apr-2017 100
1111 1 24-Apr-2017 14-Jan-2018 60
1111 1 15-Jan-2018 31-May-2019 71.429
1111 1 01-Jun-2019 31-Dec-2049 100
9 rows selected.