Click here to Skip to main content
15,889,450 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to get sum of column generated by max

table:
group             fees
1               200
1               300
2               200
2               400
2               600
3               500


get sum of max fees from each group

Answer : 300+600+500=1400
Posted
Updated 11-Feb-13 2:02am
v2

SQL
select group,sum(Fees) as TotalFees 
from
(
Select group,max(fees) as Fees
from Table
group by group
)A
 
Share this answer
 
Comments
tushar Vayangankar 11-Feb-13 8:31am    
Thanx
It should works properly:
SQL
SELECT SUM([fees]) AS MaxOfFees
FROM (
    SELECT [group], MAX([fees]) AS [fees]
    FROM YourTable
    GROUP BY [group])
 
Share this answer
 
Comments
tushar Vayangankar 11-Feb-13 8:31am    
Thanx
Maciej Los 11-Feb-13 8:39am    
You're welcome ;)
If my answer was helpful, please rate it.
Try:
SQL
SELECT SUM(maximum) FROM 
   (SELECT MAX(fees) as maximum FROM myTable GROUP BY [group]) a
 
Share this answer
 
Comments
tushar Vayangankar 11-Feb-13 8:31am    
Thanx

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900