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)
 group by, top N of each group

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2004-11-02 : 07:19:38
ned writes "Hi,

How can I set up a query to group the employees by district, but just take the top 3 employees from each district? Thx"

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2004-11-02 : 07:43:14
something like:

Select id, comment, district
From myTable as t1
Where (Select count(distinct district) from myTable Where id = t1.id and district >= t1.district) <= 3
Order By id, district desc

Go with the flow & have fun! Else fight the flow
Go to Top of Page
   

- Advertisement -