假设我有表 foo
美国广播公司 =============== 1 1 1 1 2 3 1 2 4 1 3 6 2 2 6
我想要所有 C 的集合,其中我有一个重复的 AB。就像是:
select all(C) from foo group by a, b having count(b) > 1
我希望结果是
全部(C) === 3 4
在 Oracle SQL 中是否有一种简单的方法可以做到这一点?
SELECT t1.c
FROM foo t1
JOIN foo t2 ON (t1.a = t2.a AND
t1.b = t2.b AND
t1.rowid != t2.rowid)
应该给你你所追求的。更有效的可能是使用分析函数
SELECT c
FROM (SELECT f.*,
count(*) over (partition by a, b) cnt
FROM foo f)
WHERE cnt > 1
尝试这个:
SELECT C
FROM
(select C, COUNT(*) OVER(PARTITION BY A, B) AS DUPLICATES
from MY_TABLE) AS RESULTS
WHERE DUPLICATES > 1
我想到了。我用了
select f.c from foo f
join (select a, b from foo group by a, b having count(c) > 1) dupes
on dupes.a = f.a and dupes.b = f.b;