,
SELECT a.*
FROM
(
SELECT id, amount, count(1) OVER (PARTITION BY amount) num_dup
FROM table1
)a
WHERE a.num_dup >1
更新。如果你只关心不同的ID,使用COUNT(DISTINCT id)
代替COUNT(1)
更多的例子。
随着加入另一个表
SELECT a.*
FROM
(
SELECT a.id, a.amount,
count(distinct a.id) OVER (PARTITION BY a.amount) num_dup
FROM table1 a
INNER JOIN table2 b ON (b.id = a.id)
)a
WHERE a.num_dup >1
无窗的功能和无table1.id:
SELECT a.amount, count(distinct a.id)
FROM table1 a
INNER JOIN table2 b ON (b.id = a.id)
GROUP BY a.amount
HAVING count(distinct a.id) >1 ;
没有窗函数与table1.id:
SELECT b.*
FROM
(
SELECT a.amount, count(distinct a.id)
FROM table1 a
INNER JOIN table2 b ON (b.id = a.id)
GROUP BY a.amount
HAVING count(distinct a.id) >1
)a
INNER JOIN table1 b ON (b.amount = a.amount)
Thanj你UR响应。你能告诉我什么是使用功能分区 – TMS 2014-10-03 16:07:06
这是一个非常大的话题。检查Oracle文档中的“分析函数”(例如,这里是 - http://docs.oracle.com/cd/E11882_01/server.112/e26088/functions004.htm#SQLRF06174) – a1ex07 2014-10-03 16:10:31
您给出的查询完美工作。但是当我加入时它不起作用。 – TMS 2014-10-03 18:44:23