|
-
Apr 14th, 2010, 12:18 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] selecting top n rows where appears the most
I am running a select statement on an orders table (sql) . I want to select the top 5000 of the items that sold the most.- where the count of the item name appears the most.
How do I go about this?
thank you.
-
Apr 14th, 2010, 12:24 PM
#2
Re: selecting top n rows where appears the most
What is the table structure like? Basicly it is a Top N Order By Count(*)
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
Apr 14th, 2010, 12:34 PM
#3
Thread Starter
Hyperactive Member
Re: selecting top n rows where appears the most
Just ordernumber, itemid, itemname, date....
I need to select the top 5000 itemids which sold the most(appear the most in the table.)
thank you.
-
Apr 14th, 2010, 12:38 PM
#4
Re: selecting top n rows where appears the most
try this:
sql Code:
Select Top 5000 itemid,itemname,ordernumber,count(*) from tableName Group by itemid,itemname,ordernumber Order by count(*) desc
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
Apr 14th, 2010, 12:44 PM
#5
Thread Starter
Hyperactive Member
Re: selecting top n rows where appears the most
-
Apr 14th, 2010, 12:46 PM
#6
Re: [RESOLVED] selecting top n rows where appears the most
You might want to leave off OrderNumber there... I think it will mess up the results.
Sometimes the Programmer
Sometimes the DBA
Mazz1
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|