MySQL Workbench - 使用 WHERE 子句的 UPDATE 语句
我正在尝试使用另一个名为“new_no2”的表-列名称“NO2”中的数据来更新一个名为“Rural”的表-列名称“NO2”。请参阅下面的代码
update Rural
set Rural.NO2 = new_no2.NO2
where Rural.Year = new_no2.Year
and Rural.Site = new_no2.Site;
但是,我一直收到错误代码:1054。“Where 子句”中的未知列“new_no2.Year”
我浏览了很多教程并尝试了很多操作,例如确保表名正确等等,但由于某种原因,它不起作用。
如果有人能澄清我可能做错了什么,那就太好了。
顺便说一句,我正在使用适用于 MacBook 的 MySQL Workbench 版本 8
谢谢 布鲁诺
I'm trying to update a table called 'Rural' - column name 'NO2', with data from another table called 'new_no2' - column name 'NO2'. see the code below
update Rural
set Rural.NO2 = new_no2.NO2
where Rural.Year = new_no2.Year
and Rural.Site = new_no2.Site;
However, I keep having the error code: 1054. Unknown column 'new_no2.Year' in 'Where clause'
I went through a lot of tutorials and tried loads of things like make sure the table name is correct and so on, but for some reason, it does not work.
It will be great if someone can give some clarity on what I might be doing wrong.
by the way, I'm using MySQL workbench version 8 for MacBook
Thanks
Bruno
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用子查询:
请参阅现场演示。
如果在
new_no2
中找不到对应的值,请使用coalesce()
保持no2
不变。Use a sub query:
See live demo.
Use
coalesce()
to leaveno2
unchanged if no corresponding value is found innew_no2
.