根据条件获取一组id是连续的数据
--获取一组id连续的数据,
with aa as(
select '2020-01-01'pdate,1 id,'100'price from dual
union all
select '2020-01-01'pdate,2 id,'200'price from dual
union all
select '2020-01-01'pdate,3 id,'-300'price from dual
union all
select '2020-01-01'pdate,4 id,'-400'price from dual
union all
select '2020-01-01'pdate,5 id,'500'price from dual
union all
select '2020-01-01'pdate,6 id,'600'price from dual
union all
select '2020-01-01'pdate,7 id,'700'price from dual
union all
select '2020-01-01'pdate,8 id,'800'price from dual
)
select pdate,min(id),max(id) from(
select pdate,id,price,rownum,id-rownum x from aa
where price>0
order by pdate,id
)
group by pdate,x
原数据:要将框起来的数据作为两组
price>0的数据:
最终效果: