Reputation: 397
Okay so I have 2 columns in a table called "user". The columns are called "avatarid" and "avatarrevision"
For my query, I need to populate all row entries for "avatarid" with random numbers between 1 and 7 only where "avatarrevision" currently equals "0".
I have no idea how to write the random number stuff. Any ideas?
Upvotes: 1
Views: 94
Reputation: 10111
UPDATE user SET avatarid = avatarid + FLOOR(RAND() * (1)) + 7 where avatarrevision = 0;
Upvotes: -1
Reputation: 1269583
You can do this with update
and rand()
:
update user
set avatarid = floor(1 + rand() * 7)
where avatarrevision = 0;
Upvotes: 4