RANK

From SQLZOO
Revision as of 10:49, 13 July 2012 by Connor (Talk | contribs) (Created page with "<table align='right' border='1'> <caption>Compatibility</caption> <tr><th colspan='3'>RANK() OVER (ORDER BY f DESC)</th></tr> <tr><td align='center'>'''Engine'''</td><td align...")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
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