zoukankan      html  css  js  c++  java
  • mysql生成自然序

    角色    积分   排名
    1      100    
    2      130    
    3      134    
    4      131    
    5      123    
    6      103    
    7      104    
    
    每日按照积分重新排名一次,计算按照积分的排名前50
    常规思路:
        1、select * from xxx order by 积分 desc limit 50
        2、程序里计算  逐个update 排名 = yyy  where 角色 = 。。。
    不借助额外临时表的情况下,还有更简便的方法么?

    经过折腾试验一番,总结了一条sql:

    update xxx as t1,(select @i:=@i+1 as pm,jsid from xxxi,(SELECT @i:= 0) t order by 积分 desc limit 50) as t2
    set t1.排名=t2.pm where t1.角色=t2.角色

    但是没经过大量数据验证效率,先记录下!

  • 相关阅读:
    Visual Studio 2015 密钥
    Vue-next源码新鲜出炉一
    vue2.0基础整理
    Nest
    Nest
    Nest
    Nest
    Nest快速上手
    element-plus源码分析第一节
    获取视频第一帧,作为封面图
  • 原文地址:https://www.cnblogs.com/phper007/p/3512462.html
Copyright © 2011-2022 走看看