我正在尝试直接在mySql中执行此查询,但它无法正常工作
UPDATE article a
SET a.qte_art = (a.qte_art+(i.qte*1))
FROM(
SELECT l.qte, l.article_id_article
FROM ligne_sortie l, bon_sortie b, article a
WHERE l.bon_sortie_id_sortie = b.id_bsr
AND l.article_id_article = a.id_article
AND b.id_bsr = 1
) i
WHERE a.id_article = i.article_id_article
#1064 - 您的SQL语法出错;检查与MySQL服务器版本对应的手册,以便在'FROM(SELECT l.qte,l.article_id_article)附近使用正确的语法 来自ligne_sortie l,bon'在第3行
答案 0 :(得分:2)
您可以使用以下查询:
UPDATE
article a,
(
SELECT l.qte, l.article_id_article
FROM ligne_sortie l, bon_sortie b, article a
WHERE l.bon_sortie_id_sortie = b.id_bsr
AND l.article_id_article = a.id_article
AND b.id_bsr = 1
) i
SET a.qte_art = (a.qte_art+(i.qte*1))
WHERE a.id_article = i.article_id_article
通用查询(填写您的列/数据)将是:
UPDATE
table1 AS target,
(SELECT column1, column2 FROM table2) AS source
SET
target.column3 = source.column1
WHERE
target.column4 = source.column2
这称为"多表格语法",有关详细信息,请参阅Update syntax manpage。
答案 1 :(得分:1)
试试这段代码吧。在SET
之后删除FROMUPDATE article a SET a.qte_art = (a.qte_art+(i.qte*1)) (
SELECT l.qte, l.article_id_article
FROM ligne_sortie l, bon_sortie b, article a
WHERE l.bon_sortie_id_sortie = b.id_bsr
AND l.article_id_article = a.id_article
AND b.id_bsr = 1
) i WHERE a.id_article = i.article_id_article
答案 2 :(得分:1)
您可以使用join statement as
进行更新update article a
join ligne_sortie l on l.article_id_article = a.id_article
join bon_sortie b on l.bon_sortie_id_sortie = b.id_bsr
set a.qte_art = (a.qte_art+(l.qte*1))
where b.id_bsr = 1