我有这样的查询:
UPDATE cars SET color = "random-element"
其中随机元素是从一组中随机挑出的,比如左{红色,蓝色,绿色,橙色,蓝绿色,狗屎,紫罗兰色,黑色}
我想用其中一种颜色更新每一行的颜色。
答案 0 :(得分:0)
update cars
join
(
select id from cars
cross join
(
select 'red' as c
union all
select 'blue'
union all
select 'green'
) colors
order by rand()
) tmp on cars.id = tmp.id
set color = tmp.c