SQLTeam.com | Weblogs | Forums

Newbie Distinct - Sum

I'm trying to get a list of distinct teams and a sum of their total points but when I use the statement below I get multiple records for the same team

select distinct inv_team, sum (inv_points) as TTL from tbl_results group by inv_team, inv_points order by sum (inv_points) desc

Try this

select inv_team, sum (inv_points) as TTL 
from tbl_results 
group by inv_team
 order by 2
2 Likes

Son of a gun.... when I saw the reply I figured I'd get the inv_points not included in aggregate function.

Seems to work like a treat, off for more testing and can't thank you enough!

I think DISTINCT does a final filter after the SQL statement is executed.