17,137
社区成员
发帖
与我相关
我的任务
分享select A1,A2
from (select t1.*, row_number() over(partition by A2 order by rownum) cn
from t1)
where cn = 1;
结果:
A1 A2
-- ----------
a 1
e 2
h 3
with test as (
select 'a' as a1,1 as a2 from dual
union all
select 'b',1 from dual
union all
select 'c',1 from dual
union all
select 'd',1 from dual
union all
select 'e',2 from dual
union all
select 'f',2 from dual
union all
select 'g',2 from dual
union all
select 'h',3 from dual
union all
select 'i',3 from dual
)
select a1,a2 from (
select a1,a2,row_number() over(partition by a2 order by a1) as rn from test
) where rn = 1;