其中有一个表source:另一个表target:
执行SQL语句(需要你写的?)想得到:
这里有一个SQL语句,但是我不知道怎么分析这个SQL语句的执行计划?也就是分析此SQL的执行顺序?update target as t
set t.major=(select major from source where source_id=t.target_id)
where t.target_id=(select source_id from source where t.target_id=source_id);
执行SQL语句(需要你写的?)想得到:
这里有一个SQL语句,但是我不知道怎么分析这个SQL语句的执行计划?也就是分析此SQL的执行顺序?update target as t
set t.major=(select major from source where source_id=t.target_id)
where t.target_id=(select source_id from source where t.target_id=source_id);
SET T.MAJOR = (SELECT MAJOR FROM SOURCE WHERE SOURCE_ID = T.TARGET_ID)
WHERE T.TARGET_ID EXISTS
(SELECT 1 FROM SOURCE WHERE SOURCE_ID = T.TARGET_ID);
其中有一个表source:
mysql> select * from source;
+----+-----------+---------+
| id | source_id | major |
+----+-----------+---------+
| 1 | 111 | english |
| 2 | 222 | chinese |
| 3 | 333 | C# |
| 4 | 444 | C++ |
| 5 | 888 | JAVA |
+----+-----------+---------+
另一个表target:mysql> select * from target;
+----+-----------+---------+
| id | target_id | major |
+----+-----------+---------+
| 1 | 111 | english |
| 2 | 222 | ASP.NET |
| 3 | 333 | PHP |
| 4 | 444 | C++ |
| 5 | 999 | JAVA |
+----+-----------+---------+
执行SQL语句(需要你写的?)想得到的结果: mysql> select * from source;
+----+-----------+---------+
| id | source_id | major |
+----+-----------+---------+
| 1 | 111 | english |
| 2 | 222 | chinese |
| 3 | 333 | C# |
| 4 | 444 | C++ |
| 5 | 888 | JAVA |
+----+-----------+---------+
5 rows in set (0.00 sec)mysql> select * from target;
+----+-----------+---------+
| id | target_id | major |
+----+-----------+---------+
| 1 | 111 | english |
| 2 | 222 | chinese |
| 3 | 333 | C# |
| 4 | 444 | C++ |
| 5 | 999 | JAVA |
+----+-----------+---------+这里有一个SQL语句,但是我不知道怎么分析这个SQL语句的执行计划?也就是分析此SQL的执行顺序? update target as t
set t.major=(select major from source where source_id=t.target_id)
where t.target_id=(select source_id from source where t.target_id=source_id);
问题2: UPDATE TARGET T
SET T.MAJOR = (SELECT MAJOR FROM SOURCE WHERE SOURCE_ID = T.TARGET_ID)
WHERE T.TARGET_ID EXISTS
(SELECT 1 FROM SOURCE WHERE SOURCE_ID = T.TARGET_ID);
似乎不能执行。执行有Show Error?
好奇的是:SQL语句中的1是什么意思?写错了吗?Is it the t.target?Thanks.