Getting the value of 'foo' for the closest previous row with higher 'bar'
with data as (
   select level as foo, mod(ora_hash(level),4) as bar from dual connect by level&lt;9
)
select
  foo,
  bar,
  prev_foo
from
  data
model 
      dimension by (foo, bar)
      measures     (cast (null as number) as prev_foo,
                    cast (null as number) as store_foo
                   )
      rules        (
        store_foo[any, any] = cv(foo),
        prev_foo [any, any] = max(store_foo) [foo &lt; cv(foo), bar &gt; cv(bar)]
      );