Customer_id
複数の distinct を使用してを取得するにはProspect_id
:
select customer_id
from yourtable
group by customer_id
having count(distinct prospect_id) >1
デモで SQL Fiddle を参照してください
それらのすべての詳細を返したい場合は、Customer_Ids
次を使用できます。
select *
from yourtable t1
where exists (select customer_id
from yourtable t2
where t1.customer_id = t2.customer_id
group by customer_id
having count(distinct prospect_id) >1)
SQL Fiddle with Demoを参照してください。
これは次のように書くこともできます (thanks @ypercube ):
select *
from yourtable t1
where exists (select customer_id
from yourtable t2
where t1.customer_id = t2.customer_id
and t1.prospect_id <> t2.prospect_id)
デモで SQL Fiddle を参照してください