标签:target continue case update span man targe log com
第一个需求是根据A字段进行排序,排序结果更新到B字段
简单搜索之后,很快得到答案
http://dev.mysql.com/doc/refman/5.7/en/update.html
SET @a=0; UPDATE tableName SET a = ( SELECT @a := @a +1 ) ORDER BY b ASC
第二个需求是根据A字段分组,对B字段排序,排序结果更新到C字段
SET @C = 0;SET @A = 0; UPDATE tableName SET C = ( SELECT CASE WHEN @A = A THEN @C := @C + 1 ELSE (@C := @C + 1 AND @A := A) END ) ORDER BY A,B
结果是正确了,但是不太明白为什么……
To be continue
标签:target continue case update span man targe log com
原文地址:http://www.cnblogs.com/dreamycloud/p/6146235.html