2016-04-03 53 views
0

我有這樣一個表:如何在oracle中查找與不同Rowid相似的數據?

X Y 
====== 
20 20 
20 20 
20 21 
23 22 
22 23 
21 20 

我需要找到那些ROWID的地方X=Y但他們的ROWID是不一樣的?像第一排的X和第二排的Y是一樣的,但它們在不同的行中。

+1

''ROWID''在查詢結果中兩行不會相同 – mmuzahid

+0

您需要哪個'ROWID'值?在你的輸出?例如,值'20'具有多個匹配的具有不同'ROWID'的記錄對。你想要什麼樣的價值? –

+0

爲什麼你想要rowID? –

回答

0

你可以做到這一點的方法很多,因爲你所帶來的rowid起來,這就是其中之一:

select * from yourtable tab1 join yourtable tab2 on tab1.x = tab2.y and tab1.rowid <> tab2.rowid 
0

你想重複行:

select * 
from 
(
    select x, y, rowid, count(*) over (partition by x,y) as cnt 
    from tab 
    where x=y 
) dt 
where cnt > 1 
0

請檢查,如果這個工程

select * from tab a where exists (select * from tab b where a.x=b.y and a.rowid!=b.rownid); 
+0

這是對rownum 無效的user.table.column,table.column,或列規範 – 5A9U

+0

ROWNUM是從查詢輸出行時生成的僞列 - 它不是表中的列。也許你的意思是ROWID? –

相關問題