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条答案
按热度按时间xam8gpfp1#
你失踪了
应该管用谢谢
dzhpxtsq2#
为什么这个查询不能正常工作