Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Ranking

Status
Not open for further replies.

atltechie

IS-IT--Management
Jul 18, 2003
5
KY
Hello,

I am trying to rank subscribers calls based on minutes. I want the rank to be within the each subscriber not based on every call every call in the table. I used the following query and it seems to be ranking the entire table based on minutes. Any ideas???

SELECT C1.SUBSCRIBER, C1.CALL_TO_NUMBER, C1.PRICE_PLAN, C1.SumOfMinutes,
(SELECT COUNT (SumOfMinutes)
FROM [CALL SUM MINUTES] AS C2
WHERE C2.SumOfMinutes >= C1.SumOfMinutes
AND C2.CALL_TO_NUMBER = C1.CALL_TO_NUMBER
AND C2.SUBSCRIBER = C1.SUBSCRIBER
and c2.PRICE_PLAN = C1.PRICE_PLAN) as Rank
FROM [CALL SUM MINUTES] AS C1;
 
There is no GroupBy.

Try grouping by Subscriber.

Sam_F
"90% of the problem is asking the right question.
 
Something like this ?
SELECT C1.SUBSCRIBER, C1.CALL_TO_NUMBER, C1.PRICE_PLAN, C1.SumOfMinutes,
(SELECT COUNT (SumOfMinutes)
FROM [CALL SUM MINUTES] AS C2
WHERE C2.SumOfMinutes >= C1.SumOfMinutes
AND C2.SUBSCRIBER = C1.SUBSCRIBER) as Rank
FROM [CALL SUM MINUTES] AS C1;

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top