Created
April 11, 2012 17:19
-
-
Save moxie/2360665 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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