gpt4 book ai didi

mysql - 如何向 mySQL 更新查询添加条件语句?

转载 作者:行者123 更新时间:2023-11-29 15:52:30 26 4
gpt4 key购买 nike

我有以下 mySQL 更新查询。如何添加条件 WHEN 语句,其中表示 if Status =“PS”更改为“PE”,if Status =“DS”更改为“DE”

我不确定如何用正确的语法编写它。

 UPDATE Equipment SET delivery_time = "5 pm",
stop_sequence = "Stop 2"
WHERE (status = "Fixed" or status = "Broken")
AND customer = "Mary" AND driver = "Pete"

最佳答案

使用案例

 UPDATE Equipment SET delivery_time = '5 pm',
stop_sequence = 'Stop 2',
status = case status when 'PS' then 'PE' when 'DS' Then 'DE'
else status end
WHERE status in ('Fixed' 'Broken')
AND customer = 'Mary' AND driver = 'Pete'

关于mysql - 如何向 mySQL 更新查询添加条件语句?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56698988/

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