Mysql 你可以';t在FROM子句中指定要更新的目标表XXX(在子条款中使用SUM)

Mysql 你可以';t在FROM子句中指定要更新的目标表XXX(在子条款中使用SUM),mysql,sql,sql-update,self-join,mysql-error-1093,Mysql,Sql,Sql Update,Self Join,Mysql Error 1093,我正在尝试执行此查询: UPDATE arc_salon_credit_exposant AS asce SET asce.asce_credit_restant = ( SELECT SUM(asce_credit_restant) FROM

我正在尝试执行此查询:

        UPDATE  
            arc_salon_credit_exposant AS asce
        SET  
            asce.asce_credit_restant = 
                (
                    SELECT 
                        SUM(asce_credit_restant) 
                    FROM
                        arc_salon_credit_exposant
                    WHERE
                        asce_scre_id = '524' AND
                        asce_sexp_id = '719' AND
                        (asce_fam_id is NULL OR
                            asce_fam_id = '168')
                )
        WHERE  
            asce.asce_scre_id = '524' AND
            asce.asce_sexp_id = '719' AND
            asce.asce_fam_id is NULL
但是,我得到的只是一个mysql错误(#1093-不能在FROM子句中为update指定目标表'asce'。我在stackoverflow这里读到了一些问题(这就是为什么我尝试使用别名),但我无法让它工作。我知道我必须编写查询,以便Mysql创建临时表,但是。。我做不到。有点困在这里了

以下是表格的结构:

Column name Type    Null    Défaut
asce_id int(11) Non 
asce_scre_id    int(11) Non 
asce_sexp_id    int(11) Non 
asce_credit_restant double  Oui NULL
asce_fam_id int(11) Oui NULL
以下是一些数据:

asce\U id asce\U scre\U id asce\U sexp\U id asce\U信贷\U RETANT asce\U fam\U id

3552478854900零

17524719200零

45524719 100 168

44 524 7885 100 168


提前感谢

您需要像这样更新您的表

UPDATE  arc_salon_credit_exposant AS asce
JOIN
(     SELECT 
         asce_credit_restant.IDColumn  --<<here your Unique column for self join
         SUM(asce_credit_restant) as tot
      FROM
         arc_salon_credit_exposant
      WHERE
         asce_scre_id = '524' AND
         asce_sexp_id = '719' AND
         asce_fam_id is NULL
) A
ON asce.IDColumn = A.IDColumn
SET asce.asce_credit_restant = A.tot
WHERE  
    asce.asce_scre_id = '524' AND
    asce.asce_sexp_id = '719' AND
    asce.asce_fam_id is NULL
将arc_沙龙_信用_曝光者更新为asce
参加
(选择

asce_credit_restant.IDColumn--谢谢您的帮助,@hims056…很遗憾,我仍然有Mysql错误:(我无法让这个查询工作-即使在做了您建议的更改之后。@user1453418-您能显示数据结构和示例数据吗?