2017-08-01 90 views
0

我需要在下面的表上写一个查询才能获取记录,只有当同一个电子邮件和名称被多于一个成员共享时。在下面的例子中,我需要ResultSet作为选择重复项并根据非重复列挑选

100   [email protected]  nameA 
300   [email protected]  nameA 

Member email    name 
100   [email protected]  nameA 
100   [email protected]  nameA 
300   [email protected]  nameA 
200   [email protected]  nameB 
+0

你的问题仍然不清楚。 –

+0

根据你的描述,你为什么期望会员200?你需要会员100吗? –

回答

0

我怀疑你有错字,你的意思是100而不是200在您预期的结果。如果是这样,那么有一种方法:

with your_table(Member, email , name) as (
    select 100,'[email protected]','nameA' union all 
    select 100,'[email protected]','nameA' union all 
    select 300,'[email protected]','nameA' union all 
    select 200,'[email protected]','nameB' 
) 

-- below is actual query: 

select distinct your_table.* 
from your_table 
inner join (
    select email , name from your_table 
    group by email , name 
    having count(distinct Member) > 1 
) t 
on your_table.email = t.email and your_table.name = t.name 
+0

道歉fahad和oto,我纠正了我的结果集。它们应该是你们两个都假设的100 –