Link to home
Start Free TrialLog in
Avatar of JElster
JElsterFlag for United States of America

asked on

TOP N BY GROUP

Hi.. I have table of sales reps and products and sales..  I need the top 10 sales persons by product


name             product              sales
john                tv                          100
mary              phone                    50
john               phone                    10
bob                radio                        5
mary             clock                        59




using sql 2005 !
ASKER CERTIFIED SOLUTION
Avatar of Mike Eghtebas
Mike Eghtebas
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of JElster

ASKER

I think the server is 2000

'dense_rank' is not a recognized function name.


Any way to do in SQL2000?
try:

Select Top 10 name, product, SumSale 
From 
( 
Select name, product, Sum(sales) As SumSale
From MyTable
Group By product, name
) As D ( name, product, SumSale)
Order By product, SumSale Desc, name 

Open in new window


modified...
Avatar of JElster

ASKER

The ORDER BY clause is invalid in views, inline functions, derived tables, subqueries, and common table expressions

Any ideas?
The ORDER BY clause is invalid in views, inline functions, derived tables, and common table expressions unless top(x) and offset fetch is utilized.