简体   繁体   中英

MySQL manual id increment

I have the following query:

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

PrintID is an integer with a default value of 0. This is not the primary key. When I run the query I expect that to give one time incremental value, but it just returned NULL.

It worked after wrapping the incremental value with brackets. Thank you!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM