Difference between revisions of "RANK"

From SQLZOO
Jump to: navigation, search
Line 17: Line 17:
 
<div class='ht'>
 
<div class='ht'>
 
In this example we show the ranking, by population of those countries with a population of over 180 million.
 
In this example we show the ranking, by population of those countries with a population of over 180 million.
<source lang='sql' class='def e-oracle e-sqlserver'>
+
<source lang='sql' class='def e-oracle e-mssql'>
 
SELECT name,population,
 
SELECT name,population,
 
       RANK() OVER (ORDER BY population DESC)
 
       RANK() OVER (ORDER BY population DESC)

Revision as of 08:34, 5 July 2017

Compatibility
RANK() OVER (ORDER BY f DESC)
EngineOKAlternative
ingresNo
mysqlNo
oracleYes
postgresNo
sqlserverYes

RANK

RANK() OVER (ORDER BY f DESC) returns the rank position relative to the expression f.

  RANK() OVER (ORDER BY f DESC) 

In this example we show the ranking, by population of those countries with a population of over 180 million.

SELECT name,population,
       RANK() OVER (ORDER BY population DESC)
       AS r
FROM bbc WHERE population>180000000
ORDER BY name

See also