select * from (
select * from tab where a<2 and c=1 order by a)  where rownum=1
没太明白你的意思

解决方案 »

  1.   

    with t as
     (select 1 a, 2 b, 3 c
        from dual
      union all
      select 2 a, 3 b, 1 c
        from dual
      union all
      select 2 a, 4 b, 3 c
        from dual
      union all
      select 2 a, 5 b, 1 c
        from dual
      union all
      select 4 a, 6 b, 1 c
        from dual)
    select p_b
      from (select t.*, lag(b) over(order by a) p_b, lag(c) over(order by a) p_c
              from t) t1
     where t1.a = 2
       and p_c = 1;
      

  2.   

    可以使用lag函数:
       lag(col,1,null) over(partition by col order by col)
    lag函数是先分组再排序,并把当前行的上一个值放到该行中,lag(col,1,null)1表示增量字段,可以根据要求自定义,null是上一行不存在时用null代替,也可以自定义。
    对于你的要求就不要分组了:
    测试数据截图:select b
      from (select a, lag(b) over(order by a) b, lag(c) over(order by a) c
              from my_test) t
     where t.a = 2
       and t.c = 1;
    测试结果: