I want to update my table with random values from a given set, and not from another table.
eg. value1, value2, value3
and the MySQL query should update all records from the above values.
I'm looking for a similar type of solution, but with random string values from a given set: Refresh a column with a random value
Use floor(rand()*3)to generate a random number among 0, 1 and 2, then use case whento assign a value
floor(rand()*3)
case when
update test set i = (case floor(rand()*3) when 0 then 0 when 1 then 10 when 2 then 20 end);
fiddle
I would use the function elt():
elt()
update table t set col = elt(floor(rand()*3) + 1, 'value1', 'value2', 'value3');
elt() . rand() .
rand()
Try CEIL and RAND function
UPDATE `table` SET `column`=(CASE CEIL(RAND()*3) WHEN 1 THEN 'value1' WHEN 2 THEN 'value2' WHEN 3 THEN 'value3' END);
Source: https://habr.com/ru/post/1545785/More articles:Как группировать/выбирать столбец типа JSON (PG:: UndefinedFunction: ERROR: не удалось идентифицировать оператор равенства для типа json) - postgresqlCreating inline cells in XIB? - iosКак использовать HMAC в плагине Lua - Lightroom - luaPython sci-kit learn (metrics): difference between r2_score and explain_variance_score? - pythonWhy should I use a DIM statement in VBA or Excel? - vbahow to create tab menu on wordpress admin page - phpGrep and print only the corresponding word and the following words - linuxHow to choose methods for asynchronous call in C #, how to distribute asynchronous - c #How to place a table inside an inline block element where cells have a percentage width - htmlDetecting an approaching object - c ++All Articles