我有一个名为 Crew 的表,就像这样
Crew(
ID int(11) NOT NULL UNIQUE, #every crew member has a unique ID associated with
MovieID INT(11) NOT NULL,
Name TEXT,
Position varchar(32), #role of the person in the movie
role_id int(11);
PRIMARY KEY (ID),
FOREIGN KEY (Worked_in) REFERENCES MOVIEDATABASE.Imdb(title)
)
和另一张桌子
`cast_info` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`person_id` int(11) NOT NULL,
`movie_id` int(11) NOT NULL,
`person_role_id` int(11) DEFAULT NULL,
`note` text,
`nr_order` int(11) DEFAULT NULL,
`role_id` int(11) NOT NULL,
PRIMARY KEY (`id`),
KEY `idx_pid` (`person_id`),
KEY `idx_mid` (`movie_id`),
KEY `idx_cid` (`person_role_id`),
KEY `cast_info_role_id_exists` (`role_id`)
) 我想将cast_info中movie_id的数据项复制到Crew中的MovieID,cast_info的person_id对应Crew中的ID。Crew 属于数据库“Mine”,而 role_type 表来自另一个名为“imdb”的数据库。我尝试过像这样使用插入忽略,但它卡住了很长时间并且没有完成执行。
insert ignore into Crew(MovieID) select C1.movie_id from imdb.cast_info as
C1,imdb.cast_info as C2,Crew where C1.role_id!=C2.role_id AND Crew.ID=C1.person_id;
这是有关 cast_type 表的一些信息。Crew 表大部分是空的,只填充了 ID 列,所以我不在这里发布
+----+-----------+----------+----------------+------+----------+---------+
| id | person_id | movie_id | person_role_id | note | nr_order | role_id |
+----+-----------+----------+----------------+------+----------+---------+
| 1 | 1 | 1005336 | 1 | NULL | NULL | 1 |
| 2 | 2 | 2248922 | 1 | NULL | 25 | 1 |
| 3 | 2 | 2416848 | 2 | NULL | 22 | 1 |
| 4 | 3 | 1923237 | NULL | NULL | 12 | 1 |
| 5 | 4 | 1745461 | 3 | NULL | NULL | 1 |
+----+-----------+----------+----------------+------+----------+---------+