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
 Transact-SQL (2000)
 How do I write query that gives top 100 ppl for each group?

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2005-11-22 : 07:39:49
parry writes "hi guys
How do I write query that gives top 100 ppl by their salary (highest to lowest) from each group. Each group has unique number and each group has several member let say more than 300, and there are about 125 groups. There is only table. for example

grid mem_id sal
001 1258 5987
001 2574 8754
025 8574 9857

Thanks in advance"

nr
SQLTeam MVY

12543 Posts

Posted - 2005-11-22 : 07:47:25
select *
from tbl t1
where t1.id in (select top 100 t2.id from tbl t2 where t1.grp = t2.grp order by t2.salary 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

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-11-22 : 07:47:30
Refer point 2
http://weblogs.sqlteam.com/mladenp/archive/2005/08/01/7421.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -