在concat中的mysql子查询

时间:2018-02-27 10:16:42

标签: mysql sql

我有以下查询和文件,并且工作正常。

是否可以为product_id字段(SELECT id FROM products where name ='car')执行子查询,我该如何实现?

文件:

postcode;huisnummer;toevoeging;product;datum
1775 BB;4;;CAR;02-01-2018

查询:

LOAD DATA LOCAL INFILE '$path' 
INTO TABLE `temp_loc` 
FIELDS TERMINATED BY ';' 
OPTIONALLY ENCLOSED BY '"' 
IGNORE 1 LINES 
(@postcode,@huisnummer,@toevoeging,product,datum)
SET adres = CONCAT(REPLACE(@postcode, ' ', ''),'', @huisnummer,'$',@toevoeging);

数据库列:

merged_adres , product_id, datum

1 个答案:

答案 0 :(得分:0)

答案:

LOAD DATA LOCAL INFILE '$path' 
INTO TABLE `temp_loc` 
FIELDS TERMINATED BY ';' 
OPTIONALLY ENCLOSED BY '"' 
IGNORE 1 LINES 
(@postcode,@huisnummer,@toevoeging,@product,datum)
SET adres = CONCAT(REPLACE(@postcode, ' ', ''),'', @huisnummer,'$',@toevoeging),
product = (SELECT id FROM products WHERE name = @product);