2

好的,所以我在这里需要做的是,将第一个表中具有特定名称的所有数据的总和。

SELECT sum(DKP_Change) FROM 'Attendance' WHERE Name='harrian'

然后在一个不同的表中,我需要用上一个表的总和更新 Total_DKP

SELECT Total_DKP FROM `Characters` WHERE Name='harrian'

我尝试了以下解决方案和其他一些解决方案,但没有得到任何工作结果

SELECT Total_DKP FROM `Characters` WHERE Name='harrian'
set Total_DKP = (SELECT sum(DKP_Change) FROM 'Attendance' WHERE Name='harrian')
4

3 回答 3

1

要连续更改数据,请使用以下UPDATE语句:

UPDATE Characters AS c
SET c.Total_DKP = ( SELECT SUM(a.DKP_Change) 
                    FROM Attendance AS a 
                    WHERE a.Name = 'harrian'
                  )
WHERE c.Name = 'harrian' ;
于 2012-12-07T21:36:58.770 回答
0
UPDATE `Characters` 
SET Total_DKP = (SELECT SUM(DKP_Change) FROM `Attendance` WHERE Name='harrian')
于 2012-12-07T21:36:14.550 回答
0

请尝试以下方法。

    update t1 set t1.secondcolumn = 
        (SELECT sum(blah) as blahsum
            FROM t1 b
         where b.name = 'harran'
        )            
    WHERE t1.name = 'harran'
;
于 2012-12-07T21:39:26.293 回答