开发者

Add a random number between 30 and 300 to an existing field

开发者 https://www.devze.com 2023-01-25 21:06 出处:网络
I 开发者_Go百科have looked on the net as well as here but can\'t find an answer to the following MySQL question. I\'m looking to replace the value of an existing field with a query that has a random n

I 开发者_Go百科have looked on the net as well as here but can't find an answer to the following MySQL question. I'm looking to replace the value of an existing field with a query that has a random number between 30 and 300. Reason was because I've moved galleries and had 250,000,000 views on my images and there have been lost with the migration and a lot of my members are upset that they have lost views....


UPDATE the_table SET the_field = the_field + FLOOR(RAND() * (270 + 1)) + 30


Use RAND()

UPDATE table

SET field = FLOOR(30 + (RAND() * 270));

WHERE foo = 'bar'


I think this will do the trick:

UPDATE  table SET  field =  ROUND(30 + (RAND() * 270)) WHERE id =1;
0

精彩评论

暂无评论...
验证码 换一张
取 消