1.薪水排序后薪水排名在第3--5 的员工
1)select * from(select ename,sal,rownum rn from
(select ename,sal from emp_44 where sal is not null order by sal desc) where rownum<6)where
rn>2;
2)select * from(select ename,sal,rownum rn from
(select ename,sal from emp_44 where sal is not null order by sal desc))where rn between 3 and 5;
2. 删除一张表中所有数据的方式?
1.truncate table 命令将快速删除数据表中的所有记录
2.delete 产生 rollback ,如果删除在数据量的表速度会很慢,同时会占用很多的
rollback,segments.truncate 是DLL 操作,不产生 rollback,速度会快一些。
3. 用一条sql 语句取出所有姓名有重复的学员姓名和重复的记录数.
select name, count(*) from student group by name
having count(*) > 1 order by count(*) desc;
4. 去除oracle 数据库 表中重复数据应有如下两种方法:
方法一:创建新表删除旧表法
1)create table student1 as select distinct id, name, score from student;
2 )drop table student;
3 )rename student1 to student;
方法二:使用rowid(地址)伪列
删除伪列地址除了最大地址值以外的记录
delete from temp where rowid not in (
select max(rowid) from temp group by id);
删除伪列地址除了最大地址值以外的记录
delete from temp where rowid not in (
select min(rowid) from temp group by id);