码迷,mamicode.com
首页 > 数据库 > 详细

MySQL分组修改排序序号

时间:2020-05-19 20:36:02      阅读:98      评论:0      收藏:0      [点我收藏+]

标签:color   weight   order   code   name   span   set   end   dep   

update jxgz_rymc r set Reorder = ( select i from (
SELECT
      (
          @i := CASE
          WHEN @DepartmentId = t1.DepartmentId THEN
             @i + 1
          ELSE
              1
          END
      ) AS i,
     (@DepartmentId := t1.DepartmentId),
     t1.PersonDirectoryId
 FROM
     jxgz_rymc t1,
     (
         SELECT
             @i := 0 ,@DepartmentId := ‘‘
     ) AS t2
 ORDER BY
     t1.DepartmentId,
     t1.PersonName,
     t1.PersonDirectoryId
) a where r.PersonDirectoryId = a.PersonDirectoryId);

 

MySQL分组修改排序序号

标签:color   weight   order   code   name   span   set   end   dep   

原文地址:https://www.cnblogs.com/BobXie85/p/12918883.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!