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)
 selecting top 10 most frequent item in a table

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2004-12-17 : 13:23:01
Peter writes "I have a log table constructed as follows:

id, eventtime, eventtype, userid, itemid, .....
where id, userid and itemid are guid's, eventtime is a datetime field and eventtype is an integer.

I need a query that can return the top 10 most frequent occuring itemid's that has eventtype=1

I'm completely stuck on this, and would appreciate any help i can get :)

Regards
PH"

X002548
Not Just a Number

15586 Posts

Posted - 2004-12-17 : 13:29:11
SELECT TOP 10 itemid, count(*)
FROM yourtable
WHERE eventtype = 1
GROUP BY itemid
ORDER BY 2 DESC



Brett

8-)
Go to Top of Page
   

- Advertisement -