Rank from lowest to highest

stapuff

Well-known Member
Joined
Feb 19, 2004
Messages
1,126
I have a query that I want to rank from lowest to highest based on a group (Ord)

The follow sql ranks it highest to lowest

Rank: (SELECT Count(*) FROM ZPD_Count1 As U WHERE [Rate] > [ZPD_Count1].[Rate] AND U.Ord = ZPD_Count1.Ord)+1

Returns this result

Ord Rate Rank
123456 425.36 3
123456 725.25 2
123456 895.62 1

I want it to return

Ord Rate Rank
123456 425.36 1
123456 725.25 2
123456 895.62 3

Regardless of what I try I can not return the rank to what I want it.

The best I got it to do was the following but it always skipped 1

Ord Rate Rank
123456 425.36 2
123456 725.25 3
123456 895.62 4


Any suggestions would be greatly appreciated.


stapuff
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Query the query:

Code:
Select * FROM Query1 ORDER BY Rank DESC;
Where Query1 is your saved query. (though I wonder if you couldn't put an order by in the original query ... you are asking to order your results, so I am surprised to see that there is no order by clause there).
 
Upvote 0
xenou -

I appreciate your post.

My saved query has a Ordered by, which did not help, and I did add an Ordered By to this which also did not. I do not get what is going on so that's why I posted the request for help.

Stapuff
 
Upvote 0
Can you post your entire query? What you posted looks to me like just one field from a query. It's hard to really see what's going on here. In any case, there's no order by in your posted query so I don't see how it can be ordered.
 
Upvote 0
Code:
Rank: (SELECT Count(*) 
FROM ZPD_Count1 As U 
WHERE [Rate] > [ZPD_Count1].[Rate] 
AND U.Ord = ZPD_Count1.Ord)[COLOR="Red"][B]+1[/B][/COLOR]

What about taking the +1 off the end? Does that fix the "skipping" problem for the first one?
 
Upvote 0
x -

here is the query:

SELECT ZPD_Count1.Ord, ZPD_Count1.Carrier, ZPD_Count1.Rate, (SELECT Count(*) FROM ZPD_Count1 As U WHERE [Rate] > [ZPD_Count1].[Rate] AND U.Ord = ZPD_Count1.Ord)+1 AS Rank
FROM ZPD_Count1
ORDER BY ZPD_Count1.Ord, ZPD_Count1.Rate;

The result of this is still no correct. Ranks from Highest to lowest, not lowest to highest.
 
Upvote 0
Code:
SELECT ZPD_Count1.Ord, ZPD_Count1.Carrier, ZPD_Count1.Rate, (SELECT Count(*) FROM ZPD_Count1 As U WHERE [Rate] > [ZPD_Count1].[Rate] AND U.Ord = ZPD_Count1.Ord)+1 AS Rank
FROM ZPD_Count1
ORDER BY ZPD_Count1.[COLOR="Red"]Ord[/COLOR], ZPD_Count1.Rate;

Sorry, but didn't you want this ordered by Rank?
Like this:
Code:
SELECT ZPD_Count1.Ord, ZPD_Count1.Carrier, ZPD_Count1.Rate, (SELECT Count(*) FROM ZPD_Count1 As U WHERE [Rate] > [ZPD_Count1].[Rate] AND U.Ord = ZPD_Count1.Ord)+1 AS Rank
FROM ZPD_Count1
ORDER BY [COLOR="Red"]Rank[/COLOR], ZPD_Count1.Rate;
 
Upvote 0

Forum statistics

Threads
1,224,587
Messages
6,179,735
Members
452,939
Latest member
WCrawford

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top