MySQL手动id增量
我有以下疑问:MySQL手动id增量,mysql,Mysql,我有以下疑问: SET @count = 0; UPDATE `batch_b` SET `batch_b`.`printid` = @count:=@count+1; ORDER BY postal_zone, country, airmail,company; PrintID是一个默认值为0的整数。这不是主键。 当我运行查询时,我希望它给出一次增量值,但它只是返回NULL。在用括号包装增量值后,它工作了。谢谢大家! Set @counter := 0; UPDATE `batch_b` S
SET @count = 0;
UPDATE `batch_b`
SET `batch_b`.`printid` = @count:=@count+1;
ORDER BY postal_zone, country, airmail,company;
PrintID是一个默认值为0的整数。这不是主键。
当我运行查询时,我希望它给出一次增量值,但它只是返回NULL。在用括号包装增量值后,它工作了。谢谢大家!
Set @counter := 0;
UPDATE `batch_b`
SET `batch_b`.`printid` = (@counter:=@counter+1)
ORDER BY postal_zone, country, airmail,company;
是否需要此项的可能重复:
SET@count:=0代码>?您的查询看起来应该可以运行(除了这个可能的输入错误)。我相信您需要更改Set@count=0代码>到声明@count int=0代码>