『壹』 oracle資料庫查詢去除重復的記錄,保留其中的某一條
SELECT 賬號,戶名,開戶行,是否公有,用戶ID
FROM A
WHERE A.ID IN ('000001','000002',...) -- ID參數條件
AND A.是否公有='私有'
UNION -- 與UNION ALL不同的是UNION 會自動去重復內
SELECT 賬號,戶名,開戶行容,是否公有,用戶ID
FROM A
WHERE A.ID IN ('000001','000002',...) -- ID參數條件
AND A.是否公有='公有'
AND A.ID NOT IN (SELECT ID FROM A WHERE A.是否公有='私有')
『貳』 關於oracle里過濾重復數據的問題
select A,B max(C) from tab group by A,B
『叄』 Oracle 根據列值過濾重復數據
select distinct(presonnel_id) from (select id from table_name ordet by DESC ) where rownum < 3
試試
『肆』 oracle查重復數據並顯示出來
SELECT *
FROM t_info a
WHERE ((SELECT COUNT(*)
FROM t_info
WHERE Title = a.Title) > 1)
ORDER BY Title DESC
一。查找重復記錄
1。查找全部重復記錄
Select * From 表 Where 重復欄位 In (Select 重復欄位 From 表 Group By 重復欄位 Having Count(*)>1)
2。過濾重復記錄(只顯示一條)
Select * From HZT Where ID In (Select Max(ID) From HZT Group By Title)
註:此處顯示ID最大一條記錄
二。刪除重復記錄
1。刪除全部重復記錄(慎用)
Delete 表 Where 重復欄位 In (Select 重復欄位 From 表 Group By 重復欄位 Having Count(*)>1)
2。保留一條(這個應該是大多數人所需要的 ^_^)
Delete HZT Where ID Not In (Select Max(ID) From HZT Group By Title)
註:此處保留ID最大一條記錄
1、查找表中多餘的重復記錄,重復記錄是根據單個欄位(peopleId)來判斷
select * from people
where peopleId in (select peopleId from people group by peopleId having count(peopleId) > 1)
2、刪除表中多餘的重復記錄,重復記錄是根據單個欄位(peopleId)來判斷,只留有rowid最小的記錄
delete from people
where peopleId in (select peopleId from people group by peopleId having count(peopleId) > 1)
and rowid not in (select min(rowid) from people group by peopleId having count(peopleId )>1)
3、查找表中多餘的重復記錄(多個欄位)
select * from vitae a
where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1)
4、刪除表中多餘的重復記錄(多個欄位),只留有rowid最小的記錄
delete from vitae a
where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1)
and rowid not in (select min(rowid) from vitae group by peopleId,seq having count(*)>1)
5、查找表中多餘的重復記錄(多個欄位),不包含rowid最小的記錄
select * from vitae a
where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1)
and rowid not in (select min(rowid) from vitae group by peopleId,seq having count(*)>1)
補充:
有兩個以上的重復記錄,一是完全重復的記錄,也即所有欄位均重復的記錄,二是部分關鍵欄位重復的記錄,比如Name欄位重復,而其他欄位不一定重復或都重復可以忽略。
1、對於第一種重復,比較容易解決,使用
select distinct * from tableName
就可以得到無重復記錄的結果集。
如果該表需要刪除重復的記錄(重復記錄保留1條),可以按以下方法刪除
select distinct * into #Tmp from tableName
drop table tableName
select * into tableName from #Tmp
drop table #Tmp
發生這種重復的原因是表設計不周產生的,增加唯一索引列即可解決。
2、這類重復問題通常要求保留重復記錄中的第一條記錄,操作方法如下
假設有重復的欄位為Name,Address,要求得到這兩個欄位唯一的結果集
select identity(int,1,1) as autoID, * into #Tmp from tableName
select min(autoID) as autoID into #Tmp2 from #Tmp group by Name,autoID
select * from #Tmp where autoID in(select autoID from #tmp2)
『伍』 oracle imp 導入命令 怎麼過濾重復數據
1、oracle imp 導入先建立表結構,之後對要過重的數據加上主鍵這樣導入就能過濾。
2、但不建回議在導入時過濾那樣答性能會慢,可以先進行導入後去重更簡單。
DELETE FROM tab
WHERE ROWID NOT IN(SELECT max(ROWID) from tab a
GROUP BY a.col HAVING COUNT(*) > 1)
這樣導入後很快。
『陸』 oracle資料庫的過濾問題:如何過濾兩個表中相同的部分數據。比如說A表與B表都有記錄
試試下面的SQL語句是否符合你的需求: --A:
select XX_id
from tiantiantian
where sum_date=20110420
and XX_status < 30
and XX_type in (1009, 1008, 1003, 1011)
and XX_date > to_date(20110420, 'yyyymmdd')
and not exists(
select xx_id from dididi
where sum_date=20110420
and XX_status < 30
and XX_type in (1009, 1008, 1003, 1011)
and XX_date > to_date(20110420, 'yyyymmdd'));
--B:
select XX_id
from dididi
where sum_date=20110420
and XX_status < 30
and XX_type in (2001)
and XX_date > to_date(20110420, 'yyyymmdd')
and not exists(
select xx_id from tiantiantian
where sum_date=20110420
and XX_status < 30
and XX_type in (2001)
and XX_date > to_date(20110420, 'yyyymmdd'));
『柒』 oracle查詢過濾重復相同的數據。
SELECT DISTINCT TA.QA_TYPE TYPE,
TQ.TYPE_DESCRIPTION TYPEDESCRIPTION
FROM T_QA_RULE_DEFINE TA, T_QA_CHECK TQ
WHERE TA.QA_TYPE = TQ.TYPE
AND TA.QA_CHECK_TYPE = TQ.CHECK_TYPE
AND TA.VALID_FLAG = 'Y'
只取這兩來個字源段不就行了么,是不是你想要的
『捌』 oracle查詢出來的數據如何消除重復數據
oracle查詢出來的數據消除重復數據的具體步驟如下:
1、首先我們查看錶中重復的數據。內
『玖』 oracle select 如何過濾重復值
select b.DFI_FND_FUND_ID,a.PFU_TOTAL_UNITS,sum(b.DFI_OFFER_PRICE)
from T_POLICY_FUND_UNITS a, T_DAILY_FUND_INFORMATION b
where a.PFU_FND_FUND_ID = b.DFI_FND_FUND_ID
and a.PFU_PFA_POL_POLICY_ID = '1173204101012010'
and a.PFU_LATEST_INDICATOR = 'L'
group by b.DFI_FND_FUND_ID,a.PFU_TOTAL_UNITS
『拾』 oracle查詢語句過濾重復數據問題
select distinct x,y ferom t;
select x,y from t group by x,y;
select * from t group by x,y having count(*)>1 ;--查出有重復記錄的數據,如果having count(*)=1 是查出沒有重復記錄的數據
select * from t a1 where rowid=(select max(rowid) from t a2 where a2.x=a1.x and a2.y=a1.y); --利用rowid唯一,適用於少量重復數據
還有 rank over(partition)這個函數你也可以好好看哈哦