gpt4 book ai didi

mysql - 更新列时的 IF 语句

转载 作者:太空宇宙 更新时间:2023-11-03 11:27:02 25 4
gpt4 key购买 nike

我有一个表 Products 包含以下内容:

  | Product title | price | price_sales | new_price |
1 | Product A | 100 | 80 | ??? |
2 | Product B | 100 | 0 | ??? |
3 | Product C | 400 | 200 | ??? |

我必须对所有产品进行更新查询:new_price 列必须是当前价格的 10% 折扣 列。当没有 price_sales (price_sales = 0) 时,price 列为实际价格。

结果必须是:

  | Product title | price | price_sales | new_price |
1 | Product A | 100 | 80 | 76 |
2 | Product B | 100 | 0 | 90 |
3 | Product C | 400 | 200 | 180 |

最佳答案

给你:

update tbl 
set new_price = if(price_sales > 0, price_sales * 0.9, price * 0.9)

关于mysql - 更新列时的 IF 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53408113/

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