gpt4 book ai didi

mysql - 带选择的 SQL 更新元组

转载 作者:行者123 更新时间:2023-11-29 17:47:11 24 4
gpt4 key购买 nike

update review set content = "Perfect place to eat" or "WOW" WHERE rating = 5.0;

如何在选项中使用或随机设置某些内容?

这是错误:

1292 Truncated incorrect INTEGER value: 'Perfect place to eat'
1292 Truncated incorrect INTEGER value: 'WOW'

最佳答案

您可以使用rand():

update review
set content = (case when rand() < 0.5 then 'Perfect place to eat'
else 'WOW'
end)
where rating = 5.0;

如果你有多个字符串,你可以这样做:

update review
set content = (case floor(rand() * 3)
when 0 then 'string1'
when 1 then 'string2'
when 2 then 'string3'
end)
where rating = 5.0;

关于mysql - 带选择的 SQL 更新元组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49710043/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com