select iproductid, caccount, count(caccount) as cnt, ( SELECT TOP 1 COUNT(name) FROM customer c2 WHERE c2.iproductid = c1.iproductid AND c2.caccount = c2.caccount GROUP BY name ORDER BY COUNT(name) DESC) AS AS namecount from customer c1 group by iproductid,caccount having count(caccount)>2 order by iproductid,cnt>I have a query that finds duplicate customers using the same credit card:
>select iproductid,caccount,count(caccount) as cnt >from customer c >group by iproductid,caccount >having count(caccount)>2 >order by iproductid,cnt >>
> >iproductid caccount cnt >----------- ------------------------------ ----------- >1 xxx 3 >1 yyy 3 > >>