我想重新排序显示列,以便顺序顺序且没有间隙。类似于以下可能的
UPDATE foo
INNER JOIN bar ON foo.barid = bar.id
SET foo.display = !rowcount!
WHERE bar.baz = 1
ORDER BY foo.display;
答案 0 :(得分:1)
你想要这个吗?
UPDATE foo
INNER JOIN (
SELECT t2.id, @rowNo := @rowNo + 1 AS rowcount
FROM foo t1
INNER JOIN bar t2 ON t1.barid = t2.id
INNER JOIN (SELECT @rowNo := 0) t
WHERE t2.baz = 1
ORDER BY t1.display) bar ON foo.barid = bar.id
SET foo.display = bar.rowcount