Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从csv文件上载数据时,如何更改mysql表中的特定列条目?_Mysql_Csv - Fatal编程技术网

从csv文件上载数据时,如何更改mysql表中的特定列条目?

从csv文件上载数据时,如何更改mysql表中的特定列条目?,mysql,csv,Mysql,Csv,我以如下标准方式将数据从csv文件上传到mysql表: TRUNCATE TABLE table_name; load data local infile '/path/to/file/file_name.csv' into table table_name fields terminated by ',' enclosed by '"' lines terminated by '\r\n' (id, name, type, deleted); id_1, name_1, type_1, nu

我以如下标准方式将数据从csv文件上传到mysql表:

TRUNCATE TABLE table_name;
load data local infile '/path/to/file/file_name.csv' into table table_name
fields terminated by ','
enclosed by '"'
lines terminated by '\r\n'
(id, name, type, deleted);
id_1, name_1, type_1, null
id_2, name_1, type_2, 2010-05-10
id_3, name_3, type_3, null
csv文件中的所有“已删除”列条目都具有“当前”或“已删除”值

问题:当csv数据加载到表中时,我想将csv文件中所有相应的“已删除”条目的当前日期放入表中。“当前”项为空。我该怎么做

示例:csv文件:

id_1, name_1, type_1, current
id_2, name_1, type_2, deleted
id_3, name_3, type_3, current
加载此数据后的表应如下所示:

TRUNCATE TABLE table_name;
load data local infile '/path/to/file/file_name.csv' into table table_name
fields terminated by ','
enclosed by '"'
lines terminated by '\r\n'
(id, name, type, deleted);
id_1, name_1, type_1, null
id_2, name_1, type_2, 2010-05-10
id_3, name_3, type_3, null

编辑加载csv文件后,我可能会运行另一个单独的查询。想知道是否可以在同一个查询中完成

使用另一个查询来更改这些已删除的条目非常简单。我同意这个解决方案

您可以在语法中使用SET子句:


难道你不能将CSV文件加载到一个数组中,然后遍历它吗?或者只是迭代文件本身

然后,您只需根据需要更新/添加表中每条记录的日期(如果字段[2]=“已删除”或类似的内容)