日期:2014-05-17 浏览次数:20971 次
select *
from tablename
where id in (
select id
from tablename
group by id
having count(*) > 1
)
------解决方案--------------------
with tb1 as
(
select 1 as id,3000 as sal from dual
union all
select 2 as id,2000 as sal from dual
union all
select 3 as id,4000 as sal from dual
union all
select 4 as id,5000 as sal from dual
union all
select 5 as id,7000 as sal from dual
union all
select 6 as id,6000 as sal from dual
)
select id,sal from (select id,sal from (select id,sal,row_number() over(order by sal desc) as rn from tb1) t where t.rn<=3) tt
union all
select id,sal from tb1 where id not in (select id from (select id,sal,row_number() over(order by sal desc) as rn from tb1) t where t.rn<=3);
ID SAL
---------- ----------
5 7000
6 6000
4 5000
1 3000
2 2000
3 4000