Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MySQL手动id增量_Mysql - Fatal编程技术网

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