开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜