在3张表Oracle SQL之间进行更新
我有一个问题。
我得到了3个表作为 table1
, table2
, table3
。
-
table1
- >第1列(plate
),第2列(date
) -
table2
- >第1列(plate
),第2列(brand
) -
table3
- >第1列(brand
),第2列(date
)
我想用日期
table1
用
table3
的列中的信息
我们可以加入 table1(plate)
and table2(plate)
,<代码> table2(brand)和 table3(brand)
我尝试过但给出了一个错误(无法修改列映射到非密钥保存表)
UPDATE
(
SELECT TABLE1.DATE AS OLD_DATE,
TABLE3.DATE AS NEW_DATE
FROM TABLE1
JOIN TABLE2 ON TABLE1.PLATE = TABLE2.PLATE
JOIN TABLE3 ON TABLE3.BRAND=TABLE2.BRAND
) TABLES
SET TABLES.OLD_DATE = TABLES.NEW_DATE
;
我该如何进行此更新?
感谢您的帮助
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
情况是一个不错的选择
使用
Merge
与匹配
选项对您的 代码>日期 是保留的关键字,除非双引用,否则不能用作列名。因此,引用了。顺便说一句,引用的标识符对案例敏感,我更喜欢“ date” (不是“ date” )是表的列Using
MERGE
withMATCHED
option would be a good choice for your case such asdate
is a reserved keyword and cannot be used as a column name unless double-quoted. So, that's quoted. Btw, quoted identifiers are case-sensitive, I prefered "date" (not "DATE") to be the column of the table此错误消息表明,板可能会映射到不同的品牌或品牌可能映射到不同的日期。因此,内联视图无法更新,因为它不是。
尝试一对一设置值:
This error message indicates that a Plate might map to different Brands or Brands might map to different Dates. Therefore the inline view is not updateable because it's not a key preserved table.
Try to set the value one-by-one: