设为首页 加入收藏

TOP

Oracle day05 索引_数据去重
2019-09-17 18:40:20 】 浏览:26
Tags:Oracle day05 索引 数据
索引
自动:当在表上定义一个primary key或者unique 约束条件时,oracle数据库自动创建一个对应的唯一索引.
手动:用户可以创建索引以加速查询
在一列或者多列上创建索引:
create index index on table (column[,column]...);

 

下面的索引将会提高对emp表基于ename字段的查询速度
create index emp_last_name_idx on emp(ename)

 

通过drop index 命令删掉一个索引
drop index index

 

删掉upper_last_name_idx索引
drop index upper_last_name_idx;

 

 
Top-N
语法:
select [column_list],rownum from (select [column_list] from table order by top-n_column) where rownum<=n;

 

rowid
rowid是oracle 实际存在的值,是唯一的值
rownum是一个虚拟的顺序值,前提是一定要排序
select emp.* ,rowid from emp;
 
delect from emp e where rowid not in(select min(rowid) from emp group by ename)

 

 

 
 
删除重复数据
如何只显示重复数据,或不显示重复数据
显示重复:
select * from tablename group byid having count(*)>1

 

不显示重复:
select * from tablename group byid having count(*)=1

 

删除重复数据原型:
delete from temp where rowid not in( select min(rowid) from emp group by ename having count(*)>=1)

 

 
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Redis入门简述 下一篇一条查询sql的执行流程和底层原理

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目