|
|
第二题不知这样是否更简单些
先找出后一行的数据,在找出后两行的数据,并与当前行进行比较,如果都相等说明该行的后两行数据都相等,再找出后两行数据
select t.*
from
(select t.* ,rownum rn from tmp2 t) t
where t.rn in
(select t.rn
from
(select t.*,rownum as rn,decode(t.a,lead(t.a,1,0)over(order by rownum),1,0) as nrow ,decode(t.a,lead(t.a,2,0)over(order by rownum),1,0) as nnrow from tmp2 t) t
where t.nrow = 1 and t.nnrow = 1)
or t.rn in
(select t.rn+1
from
(select t.*,rownum as rn,decode(t.a,lead(t.a,1,0)over(order by rownum),1,0) as nrow ,decode(t.a,lead(t.a,2,0)over(order by rownum),1,0) as nnrow from tmp2 t) t
where t.nrow = 1 and t.nnrow = 1)
or t.rn in
(select t.rn+2
from
(select t.*,rownum as rn,decode(t.a,lead(t.a,1,0)over(order by rownum),1,0) as nrow ,decode(t.a,lead(t.a,2,0)over(order by rownum),1,0) as nnrow from tmp2 t) t
where t.nrow = 1 and t.nnrow = 1) |
|