I am tasked with keeping a sequence number in a table sequential for a certain product ID. Apart from the argument over whether this is a good thing (I lost the argument), can this SQL statement be run in JDBC? Actually, I guess there are two statements here. We are using Spring JDBCTemplates.
SET @rank:=0;
UPDATE my_table
SET product_set=@rank:=@rank+1
WHERE product_id = '123456';
you can define a variable inside your query like this
UPDATE my_table
inner join (select @rank:= 0) r
SET product_set = @rank:=@rank+1
WHERE product_id = '123456';
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.