我有一個名爲船員表,該表是這樣的複製內容
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表的一些信息。船員表大部分是空的,只有填補這樣的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 |
+----+-----------+----------+----------------+------+----------+---------+
提供一些示例數據以理解Crew和cast_info之間的關係。 –
剛剛添加樣本數據 – user2905978
我還是不明白你想要做什麼。在你試圖插入的時候,你嘗試在Crew中插入一些東西,據說已經在那裏。 –