Difference between revisions of "RANK"

From SQLZOO
Jump to: navigation, search
(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...")
 
 
(One intermediate revision by one user not shown)
Line 15: Line 15:
 
</pre>
 
</pre>
  
<div class='qu'>
+
<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'>
+
<source lang='sql' class='def e-oracle e-sqlserver'>
 
SELECT name,population,
 
SELECT name,population,
       RANK() OVER (ORDER BY population DESC) AS r
+
       RANK() OVER (ORDER BY population DESC)
 +
      AS r
 
FROM bbc WHERE population>180000000
 
FROM bbc WHERE population>180000000
 
ORDER BY name
 
ORDER BY name
 +
</source>
 +
<source lang='sql' class='def'>
 
</source>
 
</source>
 
</div>
 
</div>
  
 
<p>See also</p>
 
<p>See also</p>

Latest revision as of 16:22, 16 July 2012

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

Personal tools
Namespaces

Variants
Actions
Reference
Toolbox
Google AdSense