473,471 Members | 1,905 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Rank function

I am trying to derive rank values in a query, just as one would with the
Rank function in Excel. Can't see how to do this elementary task. Can
anyone advise?
Nov 13 '05 #1
3 24884
"Elden Carnahan" <el***********@comcast.net> wrote in message
news:jJ********************@comcast.com...
I am trying to derive rank values in a query, just as one would with the
Rank function in Excel. Can't see how to do this elementary task. Can
anyone advise?

This ranks the products in the Northwind products table by price:

select p1.ProductName, UnitPrice,
(
select count(*) from Products p2
where p2.UnitPrice >= p1.UnitPrice
) AS Rank
from Products as p1
order by UnitPrice desc
Nov 13 '05 #2

Thanks to the person who replied. I will give that a try.
*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 13 '05 #3
"Elden Carnahan" <el***********@comcast.net> wrote in message news:<jJ********************@comcast.com>...
I am trying to derive rank values in a query, just as one would with the
Rank function in Excel. Can't see how to do this elementary task. Can
anyone advise?


If you search this group with "rank query" you'll find lots of
examples. A simple one here (despite the terrible names used):

Table A:

ID TeamNumber Points
1 1 8
2 2 4
3 3 6

and a query for it

SELECT
(SELECT COUNT(*) FROM [Table A] WHERE Points >= s.Points) AS Rank
, s.ID
, s.TeamNumber
, s.Points
FROM
[Table A] AS s
ORDER BY
s.Points DESC;

' --------------
' John Mishefske
' --------------
Nov 13 '05 #4

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

Similar topics

2
by: Tim Pascoe | last post by:
I am writing a function which I hope to use as a column value in a select query. The function recursively walks a taxonomic heirarchy, extracting the name for an organism at the taxonomic level...
2
by: Umpty | last post by:
Trying to use Microsoft Indexing Service. Here is my code using SQL Query Analyzer, which works perfectly. SELECT * FROM OPENQUERY(FileSystem, 'SELECT RANK, FileName, Characterization FROM...
10
by: Can | last post by:
I am creating an on-line survey. I want the user to have a list of choices of say 10 items that are radio buttons. They need to rank their preference. They click on preference 1, that option is...
3
by: bughunter | last post by:
I discover next problem I have view definition with rank() create view vTEST as select c1, c2, c3, ... -- problem area start , rank() over (order by c3) as RNK -- problem area stop from...
13
by: Steve Edwards | last post by:
Hi, Given a map: typedef map<long, string, greater<long> > mapOfFreq; Is there a quicker way to find the rank (i.e. index) of the elememt that has the long value of x? At the moment I'm...
2
by: nabeel.girgis | last post by:
When I compile, I get two error messages per member function I defined in my class declaration. The first error states the function name and says that it already has a body. While the second...
3
by: shyamg | last post by:
hi all, This javascript is working IE but not working in FIreFox, validating text fields. var dealerid = new keybEdit('abcdefghijklmnopqurstuvwxyz01234567890 ','Alpha-numeric input only.'); ...
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
debasisdas
by: debasisdas | last post by:
CUME_DIST:- ============= THIS FUNCTION CALCULATES THE RATIO OF THE NUMBER OF ROWS THAT HAVE A LESSER OR EQUAL RANKING TO THE TOTAL NO OF ROWS IN THE PARTITION. PERCENT_RANK:-THIS FUNCTION...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
1
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.