MySQL / SQL查询有错误

时间:2015-01-13 07:14:52

标签: mysql sql

我在下面有这个查询,其中有很多错误。

有没有人知道MySQL / SQL足以修复错误?

UPDATE shopproducts AS wesp
JOIN currencies AS wec
JOIN shopcategories AS wesc
JOIN shops AS wes
IF(wesc.adelivery = 1)
    SET wesp.totalprice = ROUND(wesp.price / 100 * wec.value, 0) + wes.adelivery
ELSE IF(wesc.bdelivery = 1)
    SET wesp.totalprice = ROUND(wesp.price / 100 * wec.value, 0) + wes.bdelivery
ELSE
    IF(wesp.price <= wes.freedelivery)
        SET wesp.totalprice = ROUND(wesp.price / 100 * wec.value, 0)
    ELSE
        SET wesp.totalprice = ROUND(wesp.price / 100 * wec.value, 0) + wes.stddelivery
WHERE wesp.currency = wec.name
AND wesp.sortcategory = wesc.category
AND wesp.shop = wes.name

谢谢!

1 个答案:

答案 0 :(得分:1)

使用这种方式,

UPDATE shopproducts AS wesp
JOIN currencies AS wec
JOIN shopcategories AS wesc
JOIN shops AS wes
SET wesp.totalprice = case when (wesc.adelivery = 1) then ROUND(wesp.price / 100 * wec.value, 0) + wes.adelivery .....(like this way all the when) end  

WHERE wesp.currency = wec.name
AND wesp.sortcategory = wesc.category
AND wesp.shop = wes.name