MySQL 在 '' 附近使用正确语法的服务器版本
MySQL server version for the right syntax to use near ''
我有 Mysql 查询问题。我的查询是
UPDATE oc_product p
INNER JOIN oc_currency as c
ON p.price2_currency_code=c.`code`
SET p.price=CASE WHEN p.price2_currency_code='EUR' THEN p.price2*c.`value`
WHEN p.price2_currency_code='USD' THEN p.price2*c.`value`
ELSE p.price;
我总是
[Err] 1064 - You have an error in your SQL syntax; check the manual
that corresponds to your MySQL server version for the right syntax to
use near '' at line 4
尝试以下查询:
update p
set p.price = (case when p.price2_currency_code='EUR'
then p.price2*c.`value`
when p.price2_currency_code='USD' then p.price2*c.`value`
else p.price end)
from oc_product p
join oc_currency c
on p.price2_currency_code=c.`code`;
可能你错过了END
UPDATE oc_product p
INNER JOIN oc_currency as c
ON p.price2_currency_code=c.`code`
SET p.price=CASE WHEN p.price2_currency_code='EUR' THEN p.price2*c.`value`
WHEN p.price2_currency_code='USD' THEN p.price2*c.`value`
ELSE p.price
END
$sql = "
UPDATE oc_product AS p
INNER JOIN oc_currency as c
ON p.price2_currency_code=c.`code`
SET p.price=case WHEN p.price2_currency_code='EUR' THEN p.price2*c.`value`
WHEN p.price2_currency_code='USD' THEN p.price2*c.`value`
ELSE p.price
END";
您只有两个条件,因此您也可以使用比 CASE
更简单的 IF
UPDATE oc_product p
INNER JOIN oc_currency as c
ON p.price2_currency_code=c.`code`
SET p.price=
IF(p.price2_currency_code='EUR' OR p.price2_currency_code='USD', p.price2*c.`value`, p.price);
在您的查询末尾添加一个 END CASE,一切就绪。
UPDATE oc_product p
INNER JOIN oc_currency as c
ON p.price2_currency_code=c.`code`
SET p.price=CASE WHEN p.price2_currency_code='EUR' THEN p.price2*c.`value`
WHEN p.price2_currency_code='USD' THEN p.price2*c.`value`
ELSE p.price
END CASE;
我有 Mysql 查询问题。我的查询是
UPDATE oc_product p
INNER JOIN oc_currency as c
ON p.price2_currency_code=c.`code`
SET p.price=CASE WHEN p.price2_currency_code='EUR' THEN p.price2*c.`value`
WHEN p.price2_currency_code='USD' THEN p.price2*c.`value`
ELSE p.price;
我总是
[Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 4
尝试以下查询:
update p
set p.price = (case when p.price2_currency_code='EUR'
then p.price2*c.`value`
when p.price2_currency_code='USD' then p.price2*c.`value`
else p.price end)
from oc_product p
join oc_currency c
on p.price2_currency_code=c.`code`;
可能你错过了END
UPDATE oc_product p
INNER JOIN oc_currency as c
ON p.price2_currency_code=c.`code`
SET p.price=CASE WHEN p.price2_currency_code='EUR' THEN p.price2*c.`value`
WHEN p.price2_currency_code='USD' THEN p.price2*c.`value`
ELSE p.price
END
$sql = "
UPDATE oc_product AS p
INNER JOIN oc_currency as c
ON p.price2_currency_code=c.`code`
SET p.price=case WHEN p.price2_currency_code='EUR' THEN p.price2*c.`value`
WHEN p.price2_currency_code='USD' THEN p.price2*c.`value`
ELSE p.price
END";
您只有两个条件,因此您也可以使用比 CASE
IF
UPDATE oc_product p
INNER JOIN oc_currency as c
ON p.price2_currency_code=c.`code`
SET p.price=
IF(p.price2_currency_code='EUR' OR p.price2_currency_code='USD', p.price2*c.`value`, p.price);
在您的查询末尾添加一个 END CASE,一切就绪。
UPDATE oc_product p
INNER JOIN oc_currency as c
ON p.price2_currency_code=c.`code`
SET p.price=CASE WHEN p.price2_currency_code='EUR' THEN p.price2*c.`value`
WHEN p.price2_currency_code='USD' THEN p.price2*c.`value`
ELSE p.price
END CASE;