Return to Snippet

Revision: 70285
at January 3, 2016 14:10 by ktrout


Initial Code
-- calculate rank ( with ties ) over points table
-- leaguetable { id, team, pts, league }
select leag.id, leag.team, leag.pts,
@rnk := if(leag.pts = @lag, @rnk,
           if(@lag := leag.pts, @rnk + 1, @rnk + 1)) as rnk
from leaguetable leag
cross join ( select @rnk := 0, @lag := null ) params
where league = 'FA Cup'
order by leag.pts desc
;

Initial URL
http://sqlfiddle.com/#!9/b109e/3

Initial Description
calculate rank ( with ties ) over points table

Initial Title
mysql rank with ties

Initial Tags
mysql

Initial Language
SQL