Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/72.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
Mysql 是否可以将加载数据填充与SELECT/WHERE(如插入…选择)一起使用?_Mysql_Sql - Fatal编程技术网

Mysql 是否可以将加载数据填充与SELECT/WHERE(如插入…选择)一起使用?

Mysql 是否可以将加载数据填充与SELECT/WHERE(如插入…选择)一起使用?,mysql,sql,Mysql,Sql,我有一张大学桌和一张系桌。college表有两列:id和name,还有一些行: +----+-------------------------+ | id | name | +----+-------------------------+ | 1 | College of Engineering | | 2 | College of Science | | 3 | College of Business | | 4 | Colle

我有一张大学桌和一张系桌。college表有两列:id和name,还有一些行:

+----+-------------------------+
| id |          name           |
+----+-------------------------+
|  1 | College of Engineering  |
|  2 | College of Science      |
|  3 | College of Business     |
|  4 | College of Liberal Arts |
+----+-------------------------+
该系有三栏:id、姓名和学院id

+----+------+------------+
| id | name | college_id |
+----+------+------------+
现在我有了一个csv文件,其中包含一个系的列表及其学院名称:

Department of Computer Science, College of Engineering
Department of Mathematics, College of Science
Department of Histiry, College of Liberal Arts
现在我想使用load DATA INFILE将csv文件加载到DEPARTY表中,但DEPARTEBEMT表需要学院id,而csv文件只有学院名称。是否可以在LOAD DATA INFILE子句中获取学院id

谢谢大家!

LOAD DATA LOCAL INFILE 'path to .csv' INTO TABLE college
FIELDS TERMINATED BY ',' 
ENCLOSED BY '"' 
LINES TERMINATED BY '\n'
IGNORE 1 LINES
(name) 

我希望id是自动递增的。使用这个想法创建College表,然后创建一个包含csv文件中所有列的临时表。然后使用temp表和college表,您可以填写department表。

您可以将其加载到临时表中,或者创建一个临时列并从中进行操作吗?这就是一个示例!我是在一般地解释!OP清楚地提供了他的表的详细信息,为什么还要提供一般性查询。请尝试为OP的特定上下文构造查询。这将有助于使您的答案更相关、更好,谢谢您的建议:请查看我的编辑并验证它是否符合您试图传达的内容:请随时回复,这正是我想要解释的: