oracle去重等基础问题
--去重查詢方法一:根據(jù)id
select * from sxe where id in(select min(id) from sxe group by username) order by id asc;
--去重查詢方法二:根據(jù)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;
--去重查詢方法三:根據(jù)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;
--去重刪除方法一:根據(jù)ID
delete from sxe where id not in (select min(id) from sxe group by username);
--去重刪除方法二:根據(jù)rownum
--delete from (select s.*,rownum from sxe s) x where rownum not in (select min(rownum) from sxe group by username);
--去重刪除方法三:根據(jù)rowid
delete from sxe where rowid not in (select min(rowid) from sxe group by username);
?
Disctinct關(guān)鍵詞多列問題:
?
關(guān)于數(shù)據(jù)遷移,如何處理大數(shù)據(jù)量重復問題?針對Oracle
create table table1 selet * from table2; --按照table2的結(jié)構(gòu)創(chuàng)建table1,并將table2的數(shù)據(jù)導入table1;
create table table1 select * from table2 where 1 = 2; --按照table2的結(jié)構(gòu)創(chuàng)建table1,但不導入數(shù)據(jù);
開發(fā)過程中,如果涉及的數(shù)據(jù)量小的情況下刪除可以用簡單的sql執(zhí)行。但是數(shù)據(jù)量很大的遷移,百萬千萬級的數(shù)據(jù)量,性能是瓶頸的發(fā)生點;
因為查詢需要時間,執(zhí)行刪除需要時間,刪除完畢執(zhí)行事務(wù)需要時間,因此性能基本上為零,弄不好數(shù)據(jù)庫假死,甚至電腦假死。
所我的大數(shù)據(jù)遷移經(jīng)驗就是:
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;
?
關(guān)于數(shù)據(jù)庫表結(jié)構(gòu)編輯,針對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;
轉(zhuǎn)載于:https://www.cnblogs.com/lcngu/p/4976287.html
總結(jié)
以上是生活随笔為你收集整理的oracle去重等基础问题的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [ay原创作品]用wpf写了个模仿36K
- 下一篇: 手机端viewport的设置规范