select * from dm_loanplanratio t where to_char(t.enddate,'yyyy')='2016' order by t.enddate
我想获取 最后一列值 变化的前后日期,11行和12行 的数据
可以尝试降序排序的方式查询,取前两行数据
考虑错位相减,不等于零的列,可以考虑函数lead
从需求看,你只需要planratio发生变化的数据,也就是不发生变化的数据过滤掉就行了,用窗口函数,大概是下边这个样子:
select * from (select startdate,planratio,ROW_NUMBER over(partition by planratio order by startdate ) rn from dm_oanplanratio a)
where rn = 1