Java知识总结--数据库

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 enam,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 是DDL操作,不产生rollback,速度会快些。

3 用一条sql语句取出所有姓名有重复的学员姓名和重复的记录数

Select name,count(*) from student group by name having count(*)>1 order by       count(*)desc;

4 去除oracle数据库 表中重复数据应有如下两种方法:

方法一:创建新表删除旧表法

1)create student1 as select distinct id,name,score from student;

2)drop table student;

3)rename strudent1 to student;

方法二:使用rowid(地址)伪列

删除伪列地址除了最大地址值以外的记录

delete from temp where rowid not in(select max(rowid) from temp group by id);

删除伪列地址除了最小地址值以外的记录

delete from temp where rowid not (select min(rowid) from temp group by id);

转载于:https://www.cnblogs.com/zhanglilin/p/3193363.html

你可能感兴趣的:(Java知识总结--数据库)