日期:2014-05-17 浏览次数:20716 次
with t as
(select 15 a, 'tom' b, 'dog' c
from dual
union all
select 12, 'jack', 'cat'
from dual
union all
select 23, 'tom', 'dog'
from dual
union all
select 24, 'alex', 'pig'
from dual
union all
select 33, 'hunk', 'bird' from dual)
select dense_rank() over(order by nvl(d, a)) seq, a, b, c
from (select t.*, lag(a) over(partition by b order by rownum) d from t) t;
with t as
(select 15 a, 'tom' b, 'dog' c
from dual
union all
select 12, 'jack', 'cat'
from dual
union all
select 23, 'tom', 'dog'
from dual
union all
select 24, 'alex', 'pig'
from dual
union all
select 33, 'hunk', 'bird'
from dual
union all
select 34, 'hunk', 'bird'
from dual
union all
select 32, 'hunk', 'bird'
from dual
union all
select 13 a, 'tom' b, 'dog' c from dual)
select dense_rank() over(order by d) seq, a, b, c
from (select t.*, last_value(a) over(order by b) d from t) t;