0

MySQL/SQLite

I want to insert a randomly generated number (of 9 positions) into multiple rows BUT they need to be the same for all rows matched in the query.

update products set tag_seed=( SELECT ABS(RANDOM() % 999999999) ) where [...];

Partialy works... Each row will have a different random number. I need them to be same.

4

1 回答 1

0

这是合乎逻辑的,因为您将为每个更新查询生成一个新的随机数。最简单的解决方案是生成一个随机整数,将其存储在局部变量中并在查询中使用该变量:

SET @rand := (SELECT ABS(RAND() * 1000000000));
update products set tag_seed=@rand where [...];
于 2013-06-08T23:36:35.233 回答