mysql随机update,MySQLUPDATE,随机数介于1-3之间Got a big table and I want to add a column that has a randomly chosen number for each record. 1, 2, or 3.
Having a hard time. Any ideas?
解决⽅案
Try this:
UPDATE tableName SET columnName = FLOOR( 1 + RAND( ) *3 );
From the MySQL documentation for RAND:
Returns a random floating-point value v in the range 0 <= v < 1.0.mysql需要安装documentation
So in the above query, the largest value which could be generated by 1 + RAND()*3 would be 3.999999, which when floored would give 3. The smallest value would occur when RAND() returns 0, in which case this would give 1.

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。