更新查询工作

时间:2018-04-23 20:21:04

标签: php mysql join rank

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

2 个答案:

答案 0 :(得分:0)

你错过了

UPDATE tablename SET username = 'newname';

它应该有用 感谢的

答案 1 :(得分:0)

为什么不能正确使用此查询

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;