我的表中有多个ID,我必须附加值00,01,02 ... 99
id newid
1768053 176805300
1768053 176805301
1768053 176805302
1768053 176805303
. .
. .
. .
. .
1768053 176805399
我要上面在mysql中显示的newid。请尽快给我。
答案 0 :(得分:0)
假设MySQL 5.x,您需要使用用户变量通过以下方式在分区上模拟row_number:
SELECT id, id * 100 + rn AS newid
FROM (
SELECT id, @crn := CASE
WHEN @cid = id THEN @crn + 1
WHEN @cid := id THEN 1
END AS rn
FROM t, (SELECT @cid := NULL, @crn := NULL) AS x
ORDER BY id
) AS X
ORDER BY id, newid