有个排行榜的表,有个字段index表示排名(如:1,2,3,4),现在有些数据删除了,导致排名字段数据全是零散的,还有重复的情况(如,2,4,7,9),怎么把这个字段按照现在index的顺序修改成回1,2,3,4,(2改成1,4=>2,7=>3,9=>4)

解决方案 »

  1.   

    建个有自增列的表  把表里的数据导入进去  然后老表删除 新表rename
      

  2.   

    update 有个排行榜的表 t, 
    ( select a.有个字段index,count(*) as cnt
    from 有个排行榜的表 a, 有个排行榜的表 b 
    where a.有个字段index>=b.有个字段index) u
    set t.有个字段index=u.cnt
    where t.有个字段index=u.有个字段index