不好意思没看清需求,以下是Oracle代码with t as
(
select 'a' as a,1 as b from dual union all
select 'a',2 from dual union all
select 'a',3 from dual union all
select 'b',1 from dual union all
select 'b',4 from dual union all
select 'c',5 from dual union all
select 'a',1 from dual
)
select a,b from
(
select distinct t2.a,FIRST_VALUE (t2.b) over(partition by t2.g order by rownum) b,t2.g from
(
select t1.a,t1.b,t1.rn-t1.grn g from
(
select a,b,rownum rn,row_number() over(partition by a order by rownum ) grn from t order by rn
) t1
) t2
) t3