473,809 Members | 2,826 Online
Bytes | Software Development & Data Engineering Community
+ 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 24904
"Elden Carnahan" <el***********@ comcast.net> wrote in message
news:jJ******** ************@co mcast.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******* *************@c omcast.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
5438
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 requested by the user. I'm having trouble figuring out the syntax to call the function from itself (see **1), and the value returned. When I test the funciton, it says 'commands completed successfully', but nothing is returned. This is in SQL2000,...
2
1555
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 SCOPE(''"/ASPNetDemo/Resumes"'') WHERE FREETEXT(''Baione'') > 0 ORDER BY RANK DESC' )
10
2984
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 removed from the top list (choices) and appears below in a list called 'Your preferences', you keep looping until all of your preferences are made. Does this make sense? How to I set it up with Javascript? Any help is appreciated.
3
2163
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 table
13
5055
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 iterating through the map and keeping count of when I hit it.
2
18115
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 error message says to see previous definition of the function. Here is an example. These are my constructors declarations and their corresponding function code: card ();
3
2476
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.'); var dealinit = new keybEdit('abcdefghijklmnopqurstuvwxyz01234567890 ','Alpha-numeric input only.'); var dealername = new keybEdit('abcdefghijklmnopqurstuvwxyz ','Alphabets input only.'); var rank = new...
0
8669
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 Ranking. Row_number:-returns A Unique Number For Each Row Starting With 1.for Rows That Have Duplicate Values,numbers Are Arbitarily Assigned. Dense_rank:-assigns A Unique Number For Each Row Starting With 1,except For Rows That Have Duplicate...
0
4978
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 CALCULATES THE RATIO OF THE ROW'S RANKING TO THE NUMBER OF ROWS IN THE PARTITION USING THE FORMULA (RRP-1)/(NRP-1) RRP-RANK OF ROW IN PARTITION. NRP-NUMBER OF ROW IN PARTITION. BOTH OF THESE FUNCTIONS UTILIZE DENSE_RANK FOR THEIR RANKINGS AND CAN...
0
9721
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9600
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10376
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10375
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10114
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7651
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
4331
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3860
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3011
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.