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 !
Microsoft SQL Server 2005

Avatar of undefined
Last Comment
Mike Eghtebas
ASKER CERTIFIED SOLUTION
Avatar of Mike Eghtebas
Mike Eghtebas
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of JElster
JElster
Flag of United States of America image

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
JElster
Flag of United States of America image

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.
Microsoft SQL Server 2005
Microsoft SQL Server 2005

Microsoft SQL Server 2005 is a suite of relational database management system (RDBMS) products providing multi-user database access functionality.Component services include integration (SSIS), reporting (SSRS), analysis (SSAS), data quality, master data, T-SQL and performance tuning. It includes support for managing XML data and allows a database server to be exposed over web services using Tabular Data Stream (TDS) packets encapsulated within SOAP (protocol) requests.

72K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo