數據庫中有一些功能重複。Oracle SQL如何選擇多列重複項,分割它們的ID?
IE中,在一個示例表格中,如果列的國家,顏色和類型相同,則它計爲同一行。
我想拉出這些重複項。
所以給出的示例表:
Clothes
ID COUNTRY COLOR TYPE
11 China Blue PJ
22 Spain Red Pants
39 Spain Grey Pants
51 Spain Grey Pants
70 China Blue PJ
94 Spain Red Pants
我用下面的查詢:
SELECT t1.id AS id_1, t2.id AS id_2
FROM clothes t1
LEFT JOIN clothes t2
ON t1.type = t2.type AND t1.country = t2.country AND t1.color = t2.color
WHERE t1.id <> t2.id;
導致
id_1 id_2
51 39
39 51
70 11
11 70
22 94
94 22
問:有沒有辦法做到這一點這樣我沒有得到重複的行? IE,想什麼,我已經是這樣的:
id_1 id_2
51 39
70 11
22 94