下面的表格是最简单的形式。
表“pro\u details\u old”
+------+------------+--------+------------+
| id | project_no | amount | pro_date |
+------+------------+--------+------------+
| 1000 | 001/001 | 50000 | 2018-10-01 |
| 1001 | 001/002 | 25000 | 2018-10-06 |
| 1002 | 002/004 | 75000 | 2018-10-12 |
| 1003 | 002/005 | 65000 | 2018-09-22 |
| 1004 | 002/006 | 10000 | 2018-08-17 |
| 1005 | 003/002 | 12000 | 2018-10-08 |
| 1006 | 003/003 | 145000 | 2018-07-01 |
+------+------------+--------+------------+
表“pro\u details\u new”
+------+------------+--------+----------+
| id | project_no | amount | pro_date |
+------+------------+--------+----------+
| 1050 | 001/001 | 50000 | |
| 1051 | 001/002 | 25000 | |
| 1052 | 002/004 | 75000 | |
| 1053 | 002/005 | 65000 | |
| 1054 | 002/006 | 10000 | |
| 1055 | 003/002 | 12000 | |
| 1056 | 003/003 | 145000 | |
+------+------------+--------+----------+
02)因此,我需要更新“问题”表中的“发布日期”列,同时比较上述02个表中的项目编号。已插入“问题”表的参考号和金额列。预期产出如下。
+----+--------+--------+-------------+
| id | ref_no | amount | issued_date |
+----+--------+--------+-------------+
| 1 | 1050 | 50000 | 2018-10-01 |
| 2 | 1051 | 25000 | 2018-10-06 |
| 3 | 1052 | 75000 | 2018-10-12 |
| 4 | 1053 | 65000 | 2018-09-22 |
| 5 | 1054 | 10000 | 2018-08-17 |
| 6 | 1055 | 12000 | 2018-10-08 |
| 7 | 1056 | 145000 | 2018-07-01 |
+----+--------+--------+-------------+
03)我使用了以下查询。
insert into issues
set issued_date =
(select pro_date
from pro_details_old
where
pro_details_old.project_no = pro_details_new.project_no)
left join pro_details_new on pro_details_new.id = issues.ref_no
04)我不明白什么是错误的观点。有人能帮我吗?
1条答案
按热度按时间guykilcj1#
使用join更新查询
选择要在其中更新的特定数据
issuestable
使用条件如果要填充新数据表单,请插入查询
pro_details_old
&pro_details_new
然后您可以使用下面的插入查询