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)
 Top records

Author  Topic 

jung1975
Aged Yak Warrior

503 Posts

Posted - 2005-10-04 : 16:03:39
How can I get top 3 records per site?


site count
101 40
101 7
101 33
101 7
101 18
102 45
102 4
102 12
102 3
107 4
107 3
107 20
107 22
107 189



eyechart
Master Smack Fu Yak Hacker

3575 Posts

Posted - 2005-10-04 : 16:22:01
homework?

nah, probably not for someone with 240 posts already.


Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2005-10-04 : 16:35:08
SELECT Site, [Count]
FROM YourTable t
WHERE [Count] IN (SELECT TOP 3 [Count] FROM YourTable WHERE Site = t.Site ORDER BY [Count] DESC)

Tara
Go to Top of Page

Hippi
Yak Posting Veteran

63 Posts

Posted - 2005-10-04 : 17:28:36
Tara's is very nice and here is another way
select * from Table t where
(select count(*) from table tt where t.id=tt.id and tt.Count>t.Count)>=2


Go to Top of Page

jung1975
Aged Yak Warrior

503 Posts

Posted - 2005-10-04 : 18:47:25
quote:
Originally posted by eyechart

homework?

nah, probably not for someone with 240 posts already.






what homework?


Go to Top of Page

jung1975
Aged Yak Warrior

503 Posts

Posted - 2005-10-04 : 18:47:45
quote:
Originally posted by tduggan

SELECT Site, [Count]
FROM YourTable t
WHERE [Count] IN (SELECT TOP 3 [Count] FROM YourTable WHERE Site = t.Site ORDER BY [Count] DESC)

Tara



Thank you!


Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-10-05 : 01:15:54
Also Refer point 2 here
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 -