I need to take a list of date ranges and consolidate them. In our existing table, sometimes the FROM_DT and TO_DT are the same and the FROM_DT in the following row is 1 day after the previous row's TO_DT. I want to make it just 1 row with the FROM_DT of row 1 and the TO_DT of row 2.
CREATE TABLE ML_ORIGINAL_RANGES
(MEMBER_ID VARCHAR(3),
FROM_DT DATE FORMAT 'yyyy-mm-dd',
TO_DT DATE FORMAT 'yyyy-mm-dd');
INSERT INTO ML_ORIGINAL_RANGES ('001', '2023-08-11', '2023-08-11');
INSERT INTO ML_ORIGINAL_RANGES ('001', '2023-08-12', '2023-08-12');
INSERT INTO ML_ORIGINAL_RANGES ('001', '2023-08-13', '2023-08-15');
INSERT INTO ML_ORIGINAL_RANGES ('001', '2023-08-19', '2023-08-19');
INSERT INTO ML_ORIGINAL_RANGES ('001', '2023-08-20', '2023-08-23');
INSERT INTO ML_ORIGINAL_RANGES ('002', '2023-07-14', '2023-07-14');
INSERT INTO ML_ORIGINAL_RANGES ('002', '2023-07-14', '2023-07-17');
SELECT * FROM ML_ORIGINAL_RANGES ORDER BY MEMBER_ID, FROM_DT, TO_DT;
With that, I want:
to consolidate to: