我正在尝试更新 mysql 查询中的几个字段,但我无法调整解决方案 from here我的问题:
update m_day md1,
(select ma.col as ia, mb.col as ib
from m_day md join m_another ma on md.some=ma.some
join m_bother mb on md.someb = md.someb
where md.ID = **md1.ID**) src
set md1.A = src.ia, md1.B = src.ib
where md1.date > '2015-10-10'
我得到 [Err] 1054 - “where 子句”中的未知列“md1.ID”
此查询的目的是将一些缺失的数据添加到 md 表中。
最佳答案
您在未定义子查询的 md1 上设置相等性。您是要设置 md.id=ma.id,还是要在括号外进行限定,如下所示;
update m_day md1,
(select ma.col as ia, mb.col as ib, ma.id as id
from m_day md join m_another ma on md.some=ma.some
join m_bother mb on md.someb = md.someb) src
set md1.A = src.ia, md1.B = src.ib
where md1.date > '2015-10-10' and src.ID = md1.ID
关于mysql - 从具有多个集合的mysql中的子查询中的更新表访问列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33923703/