当else等于NULL时执行if-else语句时出现语法错误



列Old_Price用于确定列Increased_Price,如果Old_Prices小于$10,则添加10%,否则为null。

SELECT Copy_Price, 
IF (Old_Price < 10.00, 
Increased_Price = (Old_Price + (Old_Price * 0.1))
ELSE Increased_Price = NULL);

如果您只想在increased_price列中查看结果,请使用select

SELECT Copy_Price, IF(Old_Price < 10.00, Old_Price + (Old_Price * 0.1), null) Increased_Price 
from my_table  

否则,如果您想将结果存储在表中,则使用更新并设置

update my_table 
set Increased_Price =  IF (Old_Price < 10.00, Old_Price + (Old_Price * 0.1), null)

最新更新