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)
 Select top 10 records from each department

Author  Topic 

HeyDino
Starting Member

2 Posts

Posted - 2004-09-16 : 13:59:46
I've looked at other topics in this forum but I'm still struggling with this query. I have a database with 5 fields - date, dept, name, pageviews, bytes. I am trying to get the top 10 pageviews per department and I can't figure out how to get the query to move to the next department after finding the first 10 records. I ended up writing a select statement for each department. Thanks
_____________________________________________________________________


select top 10 name, sum(pageviews)as Pages, dept, date, bytes
from stats
where name <> 'other.html' and dept = 'faq'
group by name, pageviews, dept, date, bytes
order by pageviews desc

select top 10 name, sum(pageviews)as Pages, dept, date, bytes
from stats
where name <> 'other.html' and dept = 'ms'
group by name, pageviews, dept, date, bytes
order by pageviews desc

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2004-09-16 : 14:01:34
this should give you an idea:
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=39982

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

HeyDino
Starting Member

2 Posts

Posted - 2004-09-16 : 19:58:01
Thanks Spirit1, that fixed it.
Go to Top of Page
   

- Advertisement -