Last active
May 20, 2020 09:38
-
-
Save Kcko/cdcc5b4aaf60b8d5eaad9ba21588ffce to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- datetime | |
SET @MIN = '2019-06-29 00:53:27'; | |
SET @MAX = '2019-06-29 13:53:27'; | |
UPDATE tablename | |
SET columnname = TIMESTAMPADD(SECOND, FLOOR(RAND() * TIMESTAMPDIFF(SECOND, @MIN, @MAX)), @MIN) | |
-- https://stackoverflow.com/questions/24378490/update-table-with-random-values-from-given-set-of-string-values | |
-- string | |
update table t | |
set col = elt(floor(rand()*3) + 1, 'value1', 'value2', 'value3'); | |
-- or | |
UPDATE `table` | |
SET `column`=(CASE CEIL(RAND()*3) | |
WHEN 1 THEN 'value1' | |
WHEN 2 THEN 'value2' | |
WHEN 3 THEN 'value3' | |
END); | |
-- random numbet between N a M | |
-- For range (min..max( (min inclusive, max exclusive) it is: | |
FLOOR( RAND() * (max-min) + min ) | |
-- For range (min..max) (min+max inclusive) it is: | |
FLOOR( RAND() * (max-min+1) + min ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment