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.
| 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 count101 40101 7101 33101 7101 18102 45102 4102 12102 3107 4107 3107 20107 22107 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. |
 |
|
|
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 |
 |
|
|
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 |
 |
|
|
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? |
 |
|
|
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! |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
|
|
|