Posted By

ktrout on 01/03/16


Tagged

mysql rank ties


Versions (?)

mysql rank with ties


 / Published in: SQL
 

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

calculate rank ( with ties ) over points table

  1. -- calculate rank ( with ties ) over points table
  2. -- leaguetable { id, team, pts, league }
  3. SELECT leag.id, leag.team, leag.pts,
  4. @rnk := IF(leag.pts = @lag, @rnk,
  5. IF(@lag := leag.pts, @rnk + 1, @rnk + 1)) AS rnk
  6. FROM leaguetable leag
  7. CROSS JOIN ( SELECT @rnk := 0, @lag := NULL ) params
  8. WHERE league = 'FA Cup'
  9. ORDER BY leag.pts DESC
  10. ;

Report this snippet  

You need to login to post a comment.