tachomi Asked: 2014-11-27 07:51:42 +0800 CST2014-11-27 07:51:42 +0800 CST 2014-11-27 07:51:42 +0800 CST Mysql更新将子查询字段值添加到字段 772 我想更新一个字段,将其添加到子查询字段的值中。 我正在尝试这个: UPDATE table a SET a.field=(a.field+b.subfield) INNER JOIN (SELECT subid, subfield FROM subtable WHERE ..... ) AS b ON a.id = b.subid WHERE ... 但我收到语法错误。 此操作的正确语法是怎样的? mysql update 1 个回答 Voted Best Answer RolandoMySQLDBA 2014-11-27T07:55:27+08:002014-11-27T07:55:27+08:00 请移动SET a.field=(a.field+b.subfield)之前ON a.id = b.subid和之后WHERE 因此,查询应如下所示: UPDATE table a INNER JOIN (SELECT subid, subfield FROM subtable WHERE ..... ) AS b ON a.id = b.subid SET a.field=(a.field+b.subfield) WHERE ... 试试看 !!!
请移动
SET a.field=(a.field+b.subfield)
之前ON a.id = b.subid
和之后WHERE
因此,查询应如下所示:
试试看 !!!