SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
create table tbl (start_date date, end_date date,volume int); insert tbl values ('1-Nov-21', '2-Nov-21',100), ('2-Nov-21', '3-Nov-21',10), ('3-Nov-21', '4-Nov-21',10), ('4-Nov-21', '5-Nov-21',50), ('5-Nov-21', '6-Nov-21',10), ('6-Nov-21', '7-Nov-21',20), ('7-Nov-21', '8-Nov-21',20), ('8-Nov-21', '9-Nov-21',20), ('9-Nov-21', '10-Nov-21',15); ;with cte as ( select volume, start_date, end_date from tbl union all select t.volume, cte.start_date, t.end_date from cte join tbl t on cte.volume = t.volume and cte.end_date = t.start_date), cte2 as ( select *, rn = row_number() over (partition by volume, end_date order by start_date) from cte ) select FORMAT (start_date, 'dd-mmm-yyyy') as start_date, max(end_date) end_date,volume from cte2 where rn=1 group by volume, start_date order by start_date;
Stuck with a problem? Got Error? Ask ChatGPT!
Copy Clear