I have a series of records containing some information (product type) with temporal validity.
I would like to meld together adjacent validity intervals, provided tha
Try something like:
with dat as (
select 'A' as product, sysdate-3 as start_dte, sysdate-2 as end_dte from dual
union all
select 'A' as product, sysdate-2 as start_dte, sysdate-1 as end_dte from dual
union all
select 'B' as product, sysdate-5 as start_dte, sysdate-4 as end_dte from dual
)
SELECT product,
MIN(start_dte) KEEP (DENSE_RANK FIRST ORDER BY start_dte) "Start",
MAX(end_dte) KEEP (DENSE_RANK LAST ORDER BY end_dte) "End"
FROM dat
GROUP BY product
ORDER BY product;
Output
PRODUCT Start End
A 2/24/2014 10:25:53 AM 2/26/2014 10:25:53 AM
B 2/22/2014 10:25:53 AM 2/23/2014 10:25:53 AM