Skip to content

Instantly share code, notes, and snippets.

@moxie
Created April 11, 2012 17:19
Show Gist options
  • Save moxie/2360665 to your computer and use it in GitHub Desktop.
Save moxie/2360665 to your computer and use it in GitHub Desktop.
select @rn:=@rn+1 as rank, referrals
from (
select count(referrer_id) as referrals, referrer_id from users
where referrer_id is not null
group by referrer_id
order by referrals desc) t1, (select @rn:=0) t2
-- Giving output like this
/* rank referrals
1 100
2 99
3 97
4 50
5 48
6 42 */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment