需求:select min(start_date),max(end_date),poor_num,jdlk_num,fpdw_type,ident_id from tmp001 group by poor_num,jdlk_num,fpdw_type,ident_id;
tmp001数据4条:
start_date,end_date,poor_num,jdlk_num,fpdw_type,ident_id
insert into tmp001 values(date'2019-01-01',date'2019-12-31',8,2,'产业','123456');
insert into tmp001 values(date'2020-04-01',date'2020-06-30',4,1,'其他','123456');
insert into tmp001 values(date'2020-07-01',date'2020-09-30',3,0,'其他','123456');
insert into tmp001 values(date'2020-10-01',date'2020-12-31',4,1,'其他','123456');
需要判断当年范围内,时间点是否连续,连续可直接select min(start_date),max(end_date),poor_num,jdlk_num,fpdw_type,ident_id from tmp001 group by poor_num,jdlk_num,fpdw_type,ident_id;
如上时间点不连续这条语句就会把2020-04-01和2020-10-01这两个变成一条了,但其实它们中间还有个2020-07-01这一条。
所以有问题,这样的SQL应该如何写才能达成需求呢?