select tt.ID,tt.NO,tt.q,(select max(t.q) from test t where tt.id=t.id and t.no>tt.no) maxq from test tt;

解决方案 »

  1.   

    select t.*,
           nvl((select distinct first_value(no) over(order by q desc) from test2 t1 where t1.id = t.id and t1.no > t.no),no) no1,
           nvl(max(q) over(partition by id order by no rows between 1 FOLLOWING and UNBOUNDED FOLLOWING),q) maxq
    from test2 t
    order by id,noSQL> 
      6  /ID  NO     Q NO1       MAXQ
    --- --- ---- --- ----------
    1   001    5 003         10
    1   002    9 003         10
    1   003   10 005          8
    1   004    3 005          8
    1   005    8 006          7
    1   006    7 008          7
    1   007    1 008          7
    1   008    7 009          6
    1   009    6 009          6
    2   100   65 102         32
    2   101   25 102         32
    2   102   32 103          8
    2   103    8 104          3
    2   104    3 104          314 rows selected