更新查询不起作用

wydwbb8l  于 2021-06-24  发布在  Mysql
关注(0)|答案(2)|浏览(402)
SELECT codefard,ave,class,
      IF(ave=@_last_ave,@curRank:=@curRank,@curRank:=@_sequence) AS rank,
       @_sequence:=@_sequence+1,@_last_ave:=ave
    FROM grade, (SELECT @curRank := 1, @_sequence:=1, @_last_ave:=0) r
    ORDER BY  ave DESC

这个查询可以正常工作,但当我将这个答案更新到表中时就不起作用了。

UPDATE grade JOIN (SELECT codefard,ave,class,
   IF(ave=@_last_ave,@curRank:=@curRank,@curRank:=@_sequence) AS rank,
              @_sequence:=@_sequence+1,@_last_ave:=ave
    FROM grade, (SELECT @curRank := 1, @_sequence:=1, @_last_ave:=0) r
    ORDER BY  ave DESC)as d ON grade.codefard = d.codefard SET grade.allrank=d.rank
xam8gpfp

xam8gpfp1#

你失踪了

UPDATE tablename SET username = 'newname';

应该管用谢谢

dzhpxtsq

dzhpxtsq2#

为什么这个查询不能正常工作

UPDATE player  
    JOIN (SELECT p.playerID,  
                 IF(@lastPoint <> p.points,  
                    @curRank := @curRank + @nextrank,  
                    @curRank)  AS rank,  
                 IF(@lastPoint = p.points,  
                    @nextrank := @nextrank + 1,  
                    @nextrank := 1),  
                 @lastPoint := p.points  
            FROM player p  
            JOIN (SELECT @curRank := 0, @lastPoint := 0, @nextrank := 1) r  
           ORDER BY  p.points DESC  
          ) ranks ON (ranks.playerID = player.playerID)  
SET player.rank = ranks.rank;

相关问题