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
 General SQL Server Forums
 New to SQL Server Programming
 Top N ---Rank

Author  Topic 

dim
Yak Posting Veteran

57 Posts

Posted - 2010-08-10 : 14:50:03
Hi,

I am fairy new to SQL server programming and would like guidance regarding the following scenario.

I have a table with the Sales Representative and No of calls each sales represenatative got during the day.

I need to write the query to select top 5 sales representative based on the no of calls received.

My below query gives the sales represenative along the total no of calls received during the day .....

select
Representative_Name,
sum(dbo.Sales.Number_of_Total_Calls) as Number_Of_Total_Calls
from
dbo.Sales
group by
Representative_Name

I need top 5 based on the Number_Of_Total_Calls ....

Thank you,
dim




Dp

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-08-10 : 14:56:15
[code]
select top 5 Representative_Name
from
(
select
Representative_Name,
sum(dbo.Sales.Number_of_Total_Calls) as Number_Of_Total_Calls
from
dbo.Sales
group by
Representative_Name
)t
order by Number_Of_Total_Calls desc
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-08-11 : 04:48:19
Also refer this
http://beyondrelational.com/blogs/madhivanan/archive/2008/09/12/return-top-n-rows.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -