Skip to content

Instantly share code, notes, and snippets.

@2803media
Created February 27, 2014 14:54
Show Gist options
  • Save 2803media/9251619 to your computer and use it in GitHub Desktop.
Save 2803media/9251619 to your computer and use it in GitHub Desktop.
en sql
SET @rank := 0;
SELECT nom_ville,CODGEO,nbr_habitants,@rank := @rank + 1 AS rank
FROM cm_datas
ORDER BY cast(`nbr_habitants` as decimal) DESC
en php
mysql_query("SET @rank:=0;");
$sql="
SELECT nom_ville,CODGEO,nbr_habitants,@rank := @rank + 1 AS rank
FROM cm_datas
ORDER BY cast(nbr_habitants as decimal) DESC
";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment