WEBサイト制作に関するTips

MySQL » サブクエリを使用した連番を振り直すUPDATE

SET
@i := 0;

UPDATE
`table`
SET
`order` = (@i := @i + 1)
WHERE
`id` IN (
SELECT
`id`
FROM
(
SELECT
id
FROM
`table`
WHERE
`column` = 1
ORDER BY
`date`
) AS `tmp`
)
ORDER BY
`order`;

2014-08-07 11:23:34