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 rows based on other rows

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2001-07-09 : 09:20:32
Jesper writes "Hi


Put in plain terms what I would like to do is to be able to is this. Say I had a branch network of something and that I had customerdata for these offices and that I would like to know (in this case) who the top 75% of my customers where..... How would I get by doing that?

I would like to be able to select rows in a group by clause based on
other rows and some sort of a running percentage total. I have no idea
how to accomplish this in SQL but I am sure there is a fairly simple
way of doing it.

Basically what I would like to do is:


Key1, Key2, Contrib
1, 1, 2.345
1, 2, 3.450
1, 3, 4.657
2, 1, 3.789
2, 2, 4.214
2, 3, 3.987
3, 1, 2.098
3, 2, 1.789
3, 3, 2.345



Key1 (1) one receives a total contribution of (2.345 + 3.450 + 4.657)=
10.452 from Key2 (1,2,3)

I would like to create something that would select the "top" 75%
contribution from Key2 grouped by key1.... I am using SQL server
2000 EE on W2K Advanced Server SP1.....

Result Set:

Key1, Key2
1, 3
2, 2
2, 3
3, 3
3, 1

Is this possible using SQL?

Any help would be greatly appreciated....

/Jesper"
   

- Advertisement -