当前位置: 代码迷 >> Java Web开发 >> oracle,该怎么解决
  详细解决方案

oracle,该怎么解决

热度:2295   发布时间:2013-02-25 21:16:47.0
oracle
1:请问oracle 怎么删除重复记录
2:假设员工表中有一字段,薪资,现在要查出这表的所有信息,然后按薪资从高到底排列,前三行显示薪资排名前三的信息,其余的按原来的顺序排列。请举例说明,谢谢。oracle 数据库我不是很熟悉。

------解决方案--------------------------------------------------------
1.出现次数大于1,即有重复资料的sql
SQL code
select * from tablename where id in (             select id             from tablename             group by id             having count(*) > 1             )
------解决方案--------------------------------------------------------
SQL code
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) ttunion allselect 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
  相关解决方案