Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Help with another query
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
00707822
Message ID:
00708107
Vues:
16
Try
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
>
>
>This gives me results like
>
>
>iproductid  caccount                       cnt
>----------- ------------------------------ -----------
>1           xxx                            3
>1           yyy                            3
>
>
>
>Now I want another column that tells me "of those customers using the same credit card, how many have the same last name?"
>
>I probably could do it with cursors and maybe a UDF, but is there another way using the select? When I try I correlated subquery, I can't get the number of records to be returned to me.
>TIA
--sb--
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform