dongzhi9906 2014-06-23 12:34
浏览 51
已采纳

使用ORDER BY DESC排名,但更新列

Hey I have a ladder ranking with this data:

http://i.stack.imgur.com/eNCOO.png

Ignore the wins, loses, lvl.

The problem is, on the team table I have a column for the ranking, the ranking I'm using on the table on the image is just a i variable that starts in 0 and increments 1 when finishes the while cyclo. How do I update the ranking column with the real ranking ordered by Points?

  • 写回答

1条回答 默认 最新

  • doutu9810 2014-06-23 12:38
    关注

    You can do this with an update/join:

    update rankings r join
           (select r.id, @rn := @rn + 1 as ranking
            from rankings r cross join
                 (select @rn := 0) vars
            order by points desc
           ) rp
           on r.id = rp.id
        set r.ranking = rp.ranking;
    

    The subquery uses variables to calculating the ranking.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序