473,387 Members | 1,641 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,387 software developers and data experts.

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 24879
"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
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.