mysql对不连续的排序字段重新连续排序
UPDATE table table1,
(SELECT
@sort := @sort + 1 AS 'sortNew',
a.sort,
a.id
FROM
table a,
( SELECT @sort := 0 ) b
WHERE
a.del_flag = 0
ORDER BY
a.sort) table2
set table1.sort = table2.sortNew WHERE table1.id = table2.id
mysql对不连续的排序字段重新连续排序
UPDATE table table1,
(SELECT
@sort := @sort + 1 AS 'sortNew',
a.sort,
a.id
FROM
table a,
( SELECT @sort := 0 ) b
WHERE
a.del_flag = 0
ORDER BY
a.sort) table2
set table1.sort = table2.sortNew WHERE table1.id = table2.id