Add a random number from 30 to 300 in an existing field

I looked at the network in the same way as here, but I can not find the answer to the following MySQL question. I want to replace the value of an existing field with a query with a random number from 30 to 300. The reason was that I moved the galleries and had 250,000,000 views on my images, and there they were lost with migration, and many of my members are upset that they lost sight ....

+7
sql mysql random numbers
source share
3 answers
UPDATE the_table SET the_field = the_field + FLOOR(RAND() * (270 + 1)) + 30 
+7
source share

Use RAND ()

 UPDATE table SET field = FLOOR(30 + (RAND() * 270)); WHERE foo = 'bar' 
+4
source share

I think this will do the trick:

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

All Articles