新聞中心
oracle某列內(nèi)數(shù)據(jù)去重
你這個不是對列去重。你這個是行數(shù)據(jù)。
成都創(chuàng)新互聯(lián)公司服務(wù)項(xiàng)目包括拉薩網(wǎng)站建設(shè)、拉薩網(wǎng)站制作、拉薩網(wǎng)頁制作以及拉薩網(wǎng)絡(luò)營銷策劃等。多年來,我們專注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術(shù)優(yōu)勢、行業(yè)經(jīng)驗(yàn)、深度合作伙伴關(guān)系等,向廣大中小型企業(yè)、政府機(jī)構(gòu)等提供互聯(lián)網(wǎng)行業(yè)的解決方案,拉薩網(wǎng)站推廣取得了明顯的社會效益與經(jīng)濟(jì)效益。目前,我們服務(wù)的客戶以成都為中心已經(jīng)輻射到拉薩省份的部分城市,未來相信會繼續(xù)擴(kuò)大服務(wù)區(qū)域并繼續(xù)獲得客戶的支持與信任!
對列的去重在查詢語句加distinct,例如 select distinct XXX from tablename
或者載查詢語句后面加group by
Oracle如何去重?
select distinct clom_name from table_name --利用distinct對列clom_name去重
select clom_name from table_name a
where rowid =(select max(b.rowid) from table_name b where a.clom_name=b.clom_name);
--利用rowid唯一標(biāo)識的特性對列clom_name 去重
Oracle查詢?nèi)コ財(cái)?shù)據(jù)
1。用rowid方法
據(jù)據(jù)oracle帶的rowid屬性,進(jìn)行判斷,是否存在重復(fù),語句如下:
查數(shù)據(jù):
select * from table1 a where rowid
!=(select max(rowid)
from table1 b where a.name1=b.name1 and
a.name2=b.name2......)
刪數(shù)據(jù):
delete from table1 a where rowid
!=(select max(rowid)
from table1 b where a.name1=b.name1 and
a.name2=b.name2......)
2.group by方法
查數(shù)據(jù):
select count(num), max(name) from student --列出重復(fù)的記錄數(shù),并列出他的name屬性
group by num
having count(num) 1 --按num分組后找出表中num列重復(fù),即出現(xiàn)次數(shù)大于一次
刪數(shù)據(jù):
delete from student
group by num
having count(num) 1
這樣的話就把所有重復(fù)的都刪除了。
3.用distinct方法 -對于小的表比較有用
create table table_new as select distinct *
from table1 minux
truncate table table1;
insert into table1 select * from table_new;
oracle如何消除重復(fù)列
select col1,col2,count(*)
from tab_1
group by col1,col2
having count(*) 1;
查出來重復(fù)數(shù)據(jù)了
然后
delete tab_1 a where rowid in (
select max(rowid) from tab_1 b
where a.col1=b.col1
and a.col2=b.col2
);
OK,搞定!
記住了,刪除之前一定要先備份,在查詢是不是要刪除的數(shù)據(jù),然后再刪除。
在oracle中,單表操作,怎樣根據(jù)某一列去重?
可用如下方法來進(jìn)行刪除重復(fù)的數(shù)據(jù)。
如test表中有如下數(shù)據(jù):
要將name重復(fù)的刪除,保留其中一條數(shù)據(jù),可用如下語句:
delete?from?test?where?age?not?in?(select?min(age)?from?test?group?by?name);
commit;
執(zhí)行后結(jié)果:
當(dāng)前名稱:oracle怎么對列去重 oracle 去重計(jì)數(shù)
文章位置:http://www.ef60e0e.cn/article/hjojdh.html