MySQL手动id增量

时间:2017-01-25 05:09:48

标签: mysql

我有以下查询:

SET @count = 0;
UPDATE `batch_b`
SET `batch_b`.`printid` = @count:=@count+1;
ORDER BY postal_zone, country, airmail,company;

PrintID是一个整数,默认值为0.这不是主键。 当我运行查询时,我希望给出一次增量值,但它只返回NULL。

1 个答案:

答案 0 :(得分:1)

使用括号包装增量值后,它可以正常工作。谢谢!

Set @counter := 0;
UPDATE `batch_b`
SET `batch_b`.`printid` = (@counter:=@counter+1)
ORDER BY postal_zone, country, airmail,company;