Sql order by within a group by with aggregate

Posted by NG on Stack Overflow See other posts from Stack Overflow or by NG
Published on 2010-03-13T05:32:51Z Indexed on 2010/03/13 5:35 UTC
Read the original article Hit count: 531

Filed under:

Say I have

Team/Name/Some number
Cardinals Jason 8
Cardinals Chris 5
Yankees Joba 6
Cubs Carlos 6
Cardinals Chris 6

And I want

Cardinals Jason 8
Cardinals Chris 11
Cubs Carlos 6
Yankees Joba 6

So, what I'm doing is grouping by team, grouping by name, summing by some number

However, within cardinals I want to make sure the names are in a particular order. If I just do an "order by name desc" for example then the the whole grouping gets ignored. So how can I order within a group.

© Stack Overflow or respective owner

Related posts about sql