选择重复项并根据非重复列挑选
问题描述:
我需要在下面的表上写一个查询才能获取记录,只有当同一个电子邮件和名称被多于一个成员共享时。在下面的例子中,我需要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
答
我怀疑你有错字,你的意思是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 –
你的问题仍然不清楚。 –
根据你的描述,你为什么期望会员200?你需要会员100吗? –