/ Published in: SQL

calculate rank ( with ties ) over points table
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
-- 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 ;
URL: http://sqlfiddle.com/#!9/b109e/3
Comments
