我有opencart。在产品表中是price
我添加了一些额外列的列。
我想填写价格并在价格 > 0 时使用额外数据重新计算它们,我需要在 SQL 中执行此操作。
这就是我想要做的:
IF cost_price > 0 AND shipping_cost1 > 0 AND shipping_cost2 > 0 AND margin > 0
THEN price = cost_price + shipping_cost1 + shipping_cost2_margin
ELSE price = price
据我所知,我可以用CASE
. 但是CASE
我需要更改price
为retail_price
. 我需要保留它price
我对查询的想法:
SELECT DISTINCT
*, pd.name AS name, p.image, m.name AS manufacturer,
(SELECT price = CASE
WHEN cost_price > 0 AND shipping_cost >0 AND shipping_cost1 >0 AND margin >0
THEN ((cost_price * margin) + shipping_cost + shipping_cost1 )
ELSE (price) FROM product_d.........
原始查询:
SELECT DISTINCT
*, pd.name AS name, p.image, m.name AS manufacturer,
(SELECT price FROM product_d...........
谁可以帮助或提供更好的编码提示?