MySQL列中的随机数 [英] Random Number in MySQL column
本文介绍了MySQL列中的随机数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在我的数据库列之一中添加随机数,称为喜欢",其中包含约5000行.目前,我已经尝试过像下面这样将随机数从10改为50.
I am trying to add random number in one of my database column called likes which have about 5000 row in it. currently I have tried like below to get random number from 10 to 50.
$randomnumberlike = (rand(10,50));
但这是在所有行中设置相同的数字...相反,我希望在行中设置不同的数字...任何人都可以建议我该怎么做?
but this is setting same number in all row...instead I want different number in row...anyone can please suggest how can I do it ?
谢谢
推荐答案
尝试:UPDATE Table SET fieldName = ((rand() * 1000) % 40) + 10;
由于在变量中对其进行预设时,所有内容都相同...
Because when you preset it in a variable, it'll be the same for all...
这篇关于MySQL列中的随机数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文