我试图更新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 - 未知专栏' md1.ID'在' where子句'
此查询的目的是将一些缺少的数据添加到md表中。
答案 0 :(得分:0)
您在未定义子查询的子查询上设置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