bingo-fly

可全局排序,也可以根据已有字段(sn)排序:

表(t1)结构:

查询语句:

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 ;

 更新语句:

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;

更新结果:

 

根据原文:http://bbs.csdn.net/topics/250014224 扩展,记录一下!

分类:

技术点:

相关文章:

  • 2021-10-21
  • 2022-12-23
  • 2021-12-10
  • 2022-12-23
  • 2021-12-18
  • 2021-09-27
  • 2021-09-17
  • 2021-06-18
猜你喜欢
  • 2021-10-15
  • 2021-08-04
  • 2021-11-13
  • 2021-10-02
  • 2021-06-18
  • 2019-01-16
相关资源
相似解决方案