如何使用带有 if 语句的 @column 加载数据本地 INFILE

How to LOAD DATA LOCAL INFILE using @column with if statement

我需要使用 @set on Load Data Local INFILE 根据颜色代码设置颜色

 LOAD DATA LOCAL INFILE "'.$file.'"
        INTO TABLE '.$table.'
        FIELDS TERMINATED by \',\'
        ENCLOSED BY \'"\'
        ESCAPED BY \'"\'
        LINES TERMINATED BY \'\n\'
        (Brand, @Color, @Year)
        SET
        Color = if (@Color = "1b"){ Color = "Blue" } else { Color = "Green" },
        Year = "2022"

您必须使用 if 子句的 mysql 样式

LOAD DATA LOCAL INFILE "'.$file.'"
        INTO TABLE '.$table.'
        FIELDS TERMINATED by \',\'
        ENCLOSED BY \'"\'
        ESCAPED BY \'"\'
        LINES TERMINATED BY \'\n\'
        (Brand, @Color, @Year)
        SET
        Color = if (@Color = '1b',  'Blue' ,  'Green' ),
        Year = "2022"

更多选项

LOAD DATA LOCAL INFILE "'.$file.'"
        INTO TABLE '.$table.'
        FIELDS TERMINATED by \',\'
        ENCLOSED BY \'"\'
        ESCAPED BY \'"\'
        LINES TERMINATED BY \'\n\'
        (Brand, @Color, @Year)
        SET
        Color = CASE @Color 
        WHEN '1b' THEN  'Blue' 
        WHEN '2b' THEN 'brown'
        ELSE  'Green' 
        END,
        Year = "2022"