首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

oracle,该怎么解决

2012-08-31 
oracle1:请问oracle怎么删除重复记录2:假设员工表中有一字段,薪资,现在要查出这表的所有信息,然后按薪资从

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 

热点排行