Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

distinct and group by 1

Status
Not open for further replies.

shams123

Programmer
Jan 27, 2006
81
MY
Hi guys,

I have table with data like:

Name Rank Year
AAA 123 1900
BBB 127 1910
CCC 25 1910
AAA 542 1930
....

I want to display the top 3 distinct names with their total ranks like (AAA = 674) ordered by their total rank. Something like:

Name Rank
AAA 674
BBB 127
CCC 25

I tried using the distinct clause with order by and it errored out.

I would appreciate any help over this!

Thanks!
 
A starting point:
SELECT Name, Sum(Rank)
FROM yourTable
GROUP BY Name
ORDER BY 2 DESC

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top