Skip to content

Instantly share code, notes, and snippets.

@heluvaguy
Created October 7, 2013 15:10
Show Gist options
  • Save heluvaguy/6869580 to your computer and use it in GitHub Desktop.
Save heluvaguy/6869580 to your computer and use it in GitHub Desktop.
Implement Rank in Mysql
SELECT cm_id,
@rnk:=IF(@preval <=> column, @rnk, @rnk + 1) AS rank,
@preval:=social_profile_score_absolute AS social_profile_score_absolute
FROM table
JOIN (SELECT @rnk := 1, @preval :=0) r
ORDER BY social_profile_score_absolute ASC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment