Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 selecting top 5 organizations

Author  Topic 

simflex
Constraint Violating Yak Guru

327 Posts

Posted - 2003-11-10 : 10:26:07
This is a sql server question.
I am trying to determine the first 5 organizations to that have the highest contributions and total contributions for each.

Here is the code:

select top 5 orgcodes, count(contributions) from org

First, it is giving incorrect orgs.
For instance, there are orgs that have only 1 contribution. They were displayed.
Conversely, there are orgs that have more than 10 contributions. They were not displayed.

Second, I am getting duplicate names.
For instance, rather than get hr 3 times, I would like to get one hr with a total of 3 contributions.
thank you in advance

nr
SQLTeam MVY

12543 Posts

Posted - 2003-11-10 : 11:01:04
select top 5 orgcodes, count(contributions)
from org
group by orgcodes
order by count(contributions) desc

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -