可全局排序,也能够根据已有字段(sn)排序:sql
表(t1)结构:spa
查询语句:.net
set @chengji=0; set @mingci=1; set @shunxu=0; /*sql语句*/ select xingming,chengji,mingci from (select xingming,chengji,@shunxu:=@shunxu+1, if(chengji=@chengji,@mingci,@mingci:=@shunxu) as mingci, @chengji:=chengji from t1 where sn=1 order by chengji desc) as t ;
更新语句:code
set @chengji=0; set @mingci=1; set @shunxu=0; /*sql语句*/ update t1, (select xingming,chengji, @shunxu:=@shunxu+1, if(chengji=@chengji,@mingci,@mingci:=@shunxu) as mingci, @chengji:=chengji from t1 where sn=2 order by chengji desc) as t2 set t1.mingci=t2.mingci WHERE t1.xingming=t2.xingming and t1.chengji=t2.chengji and t1.sn=2;
更新结果:blog
根据原文:http://bbs.csdn.net/topics/250014224 扩展,记录一下!排序