mysql rank with ties


/ Published in: SQL
Save to your folder(s)

calculate rank ( with ties ) over points table


Copy this code and paste it in your HTML
  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. ;

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.