Refresh random value column

I have a table:

ID | VALUE | DATE 1 | 5 | 2012-10-01 2 | 7 | 2012-10-02 3 | 3 | 2012-10-05 4 | 0 | 2012-05-07 

I want to add the top of the current value using VALUE random individually BETWEEN 1 AND 5.

Say:

 ID | VALUE | RANDOM VALUE 1 | 5 | 0 2 | 7 | 2 3 | 3 | 3 4 | 0 | 6 

NEW VALUE

 ID | VALUE 1 | 5 2 | 9 3 | 6 4 | 6 

How can I do it? All I can think of is making a cursor request type.

Any help?

+4
source share
2 answers

Try

 UPDATE TABLE SET VALUE=VALUE+ROUND(1+RAND()*4); 
+6
source

This will update the value with a random value from 1 to 5

 UPDATE TABLEA SET VALUE=FLOOR(RAND()*5)+1 
+5
source

Source: https://habr.com/ru/post/1440753/


All Articles