Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Select max sum amount
Message
 
 
À
06/09/2011 11:18:30
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
01522791
Message ID:
01522800
Vues:
35
>Hi John
>
>no because I also have several possible description groups.
> So I want the Maximum amount amongst the description groups sums for each member.
>
>Thanks
>
>Nick
;with Sums AS (select	sum(amount) as Total, ;
					member_ref, ;
					description ;
			from payments ;
				where description like '%Test%' ;
				group by member_ref, description ;
			),
Numbered as (select *, row_number() over (partition by member_ref ORDER BY Total DESC) as Rn from Sums)

select member_ref, description, Total from Numbered where Rn = 1
If it's not broken, fix it until it is.


My Blog
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform