oracle去重查询/删除,distinct多列问题解决方案!
来源:互联网 发布:京都自由行 知乎 编辑:程序博客网 时间:2024/05/19 06:47
--去重查询方法一:根据id
select * from sxe where id in(select min(id) from sxe group by username) order by id asc;--去重查询方法二:根据rownum
select * from (select s.*,rownum rn from sxe s ) x where x.rn in (select min(rownum) from sxe group by username) order by id asc;
--去重查询方法三:根据rowid
select * from (select s.*,rowid rid from sxe s) x where x.rid in (select min(rowid) from sxe group by username) order by id asc;
select s.*,rowid from sxe s where rowid in (select min(rowid) from sxe group by username) order by id asc;
--去重删除方法一:根据ID
delete from sxe where id not in (select min(id) from sxe group by username);
--去重删除方法二:根据rownum
--delete from (select s.*,rownum from sxe s) x where rownum not in (select min(rownum) from sxe group by username);
--去重删除方法三:根据rowid
delete from sxe where rowid not in (select min(rowid) from sxe group by username);
Disctinct关键词多列问题:
关于数据迁移,如何处理大数据量重复问题?针对Oracle
create table table1 selet * from table2; --按照table2的结构创建table1,并将table2的数据导入table1;
create table table1 select * from table2 where 1 = 2; --按照table2的结构创建table1,但不导入数据;
开发过程中,如果涉及的数据量小的情况下删除可以用简单的sql执行。但是数据量很大的迁移,百万千万级的数据量,性能是瓶颈的发生点;
因为查询需要时间,执行删除需要时间,删除完毕执行事务需要时间,因此性能基本上为零,弄不好数据库假死,甚至电脑假死。
所我的大数据迁移经验就是:
create table temp_table select * from table2 where id not in (select min(id) from table1 group by coln) order by coln asc;
drop table table2;
rename temp_table to table2;
关于数据库表结构编辑,针对Oracle:
增加列:
alter table table1 add column_name column_type;
修改列大小:
alter table table1 modify column_name new_column_type;
修改列名称:
alter table table1 rename column cln1 to cln2;
删除列:
alter table tabl1 drop column cln1;
- oracle去重查询/删除,distinct多列问题解决方案!
- oracle去重查询/删除,distinct多列问题解决方案!
- oracle去重查询/删除,distinct多列问题解决方案!
- sqlserver 去重查询distinct
- Oracle数据去重(不是distinct)
- oracle的去重关键字distinct
- Elasticsearch的distinct项查询(去重查询)
- distinct 和 group by 在查询多列数据去重复时的区别在哪?
- mysql distinct 去重
- Distinct自定义去重
- distinct 去重问题
- oracle 数据库 去重查询
- 数据库查询去重group by和distinct的理解
- SQL DISTINCT(去重)
- MySql 按记录查询使用distinct去重的小技巧
- oracle 去重.多条件
- mysql去重distinct和group by
- ThinkPHP去重 distinct和group by
- android 帮助页面
- lua 重新加载module
- 从技术细节看美团的架构
- 阿里云服务器中FTP以及Navicat的使用(自己用)
- MySQL数据库的严格模式
- oracle去重查询/删除,distinct多列问题解决方案!
- web.xml执行顺序
- s3c2440的网卡接口扩展
- Caused by: java.lang.ClassNotFoundException: org.hibernate.engine.jndi.JndiNameException
- 素数筛
- 注解
- curl模拟登陆
- linux下定时执行php脚本
- jquery获取当前日期的方法