0

I'm getting an error when trying to run this query:

UPDATE tbl1, tbl2 SET `tb1`.field=SUM(tbl2.grade) WHERE tbl2.word=tbl1.word

This is the error: #1111 - Invalid use of group function

I basically trying to get the sum of a field from tbl2 and insert it into tbl1

4

3 に答える 3

4

すべての単語の合計成績を計算するサブクエリに対して結合します。

UPDATE  tbl1 a
        INNER JOIN
        (
            SELECT  word, SUM(grade) totalGrade
            FROM    tbl2
            GROUP   BY word
        ) b ON a.word = b.word
SET     a.field = b.totalGrade
于 2013-10-31T15:52:29.427 に答える
1

やってみてください:

UPDATE tbl1
SET `tbl1`.field = (
    SELECT SUM(tbl2.grade)
    FROM tbl2
    WHERE tbl2.word = tbl1.word
    );
于 2013-10-31T15:52:04.593 に答える