0

已经花了一个小时搜索并尝试完成这项工作。开始讨厌mysql。我在这里做错了什么?

UPDATE product_reward pr
  LEFT JOIN product p ON (pr.product_id = p.product_id)
  LEFT JOIN product_special ps ON (pr.product_id = ps.product_id)

SELECT CASE ps.price  
  WHEN NULL
    THEN SET pr.points = ROUND(p.price * 1);
  ELSE 
    SET pr.points = ROUND(ps.price * 1);
END;

我尝试使用 normal IF ELSE,但显然这只适用于程序内部。仅当特价为 时,我才尝试根据正常价格设置积分NULL

4

1 回答 1

2

试试这个或者看看Mysql Update with if 语句

UPDATE product_reward pr
  LEFT JOIN product p ON (pr.product_id = p.product_id)
  LEFT JOIN product_special ps ON (pr.product_id = ps.product_id)

SET pr.points = ROUND(COALESCE(ps.price, p.price) * 1)
于 2013-01-20T00:17:44.357 回答