使用随机值更新列

2022-01-17 00:00:00 random sql-update sql mysql

我有一张桌子:

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

我想在当前值的顶部添加 VALUE 随机单独介于 1 和 5 之间.

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

让我们说:

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

新价值

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

我该怎么做?我能想到的就是做游标类型的查询.

How do I do this? All I can think of is by doing cursor type of query.

有什么帮助吗?

推荐答案

试试

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

相关文章