473,396 Members | 2,030 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Derive Ranking Function

I am trying to create a function that will take two columns of data
such as this:

field1 field2
d 977
a 87
c 768
b 756
b 754
a 75
d 743
c 686
e 67
a 655
a 565
b 54
c 54
e 456
c 445
c 445
e 378
d 333

And give me a result like this:

field1 field2 FunctionResult:
a 75 1
a 87 2
a 565 3
a 655 4
b 54 1
b 754 2
b 756 3
c 54 1
c 445 2
c 446 3
c 686 4
c 768 5
d 333 1
d 743 2
d 977 3
e 67 1
e 378 2
e 456 3

Notice the function result ranks the numberic column based on the
variable. Any function tips greatly appreciated!

RBollinger

Nov 13 '05 #1
2 4011
Found lots of answers in the NG, but none seem to work right. They're
all variations on this:

SELECT p1.ProductName, p1.UnitPrice, (select count(*) from Products p2
where p2.UnitPrice >= p1.UnitPrice) AS Rank
FROM Products AS p1
ORDER BY p1.UnitPrice DESC;
but the rankings are a bit odd... they'll evaluate ties kind of weird
thing rank
a 2
c 2
s 3
b 4

doing this in code would work, I think, but I would rather not go
there... any ideas anybody how to get this to work so you get a
numbering like
1,1, 3, 4? (tie for first, so no second place?)

Nov 13 '05 #2
try this query
SELECT p1.Field1, p1.Field2, (select count(*) from tblRanking p2
where p2.field1 = p1.field1 and p2.field2 <= p1.field2) AS Rank
FROM tblRanking AS p1
ORDER BY p1.Field1, p1.Field2;

Nov 13 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Petre Huile | last post by:
I have designed a site for a client, but they have hired an internet marketing person to incrase their search engine ranking and traffic. He wants to put extra-large fonts on every page which will...
5
by: ED | last post by:
I currently have vba code that ranks employees based on their average job time ordered by their region, zone, and job code. I currently have vba code that will cycle through a query and ranks each...
1
by: Joseph Bloch | last post by:
In all the threads on ranking in Access queries, I've not seen anything that deals with ranking against a subset of the query results. What I need to do is take the following query results: Dept...
0
by: Jeff Boes | last post by:
I hope this helps someone else ... I had struggled some time ago with attempts to get a rank of values query to work, but then I gave up and set it aside. I had another reason to attack it, and in...
5
by: valglad | last post by:
Hi, The question below was posted about 4 years ago and noone was able to answer it back then. I have virtually the same type of problem so would appreciate if anyone can help. Thanks ...
6
by: sara | last post by:
I hope someone can help with this. Our director wants to have a report that will have the departments (Retail stores) across the top, stores down the side and the RANKING of the YTD dept sales...
8
by: AnndieMac | last post by:
I have an Access 2002 database of inventory count results, and I have been asked to create summaries of the items with the most losses at a store, region and national level. Individually, I have been...
0
debasisdas
by: debasisdas | last post by:
Rank:-assigns A Unique Number For Each Row Starting With 1,except For Rows That Have Duplicate Values,in Which Case The Same Ranking Is Assigned And A Gap Appears In The Sequence For Each Duplicate...
0
by: Maciej Gawinecki | last post by:
Hello, Recently I've interested in quering XML document streams. They can be queried in keyword- based manner (non-structural queries), as the authors of the article "Semantic Search over XML...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.