SQL 查询更多的时间来执行,最后得到错误

SQL query more time to execute and finally get error

UPDATE member
SET member.usableSum = (SELECT usablesum
        FROM fundrecord
        WHERE (member.id= fundrecord.memberId) AND id IN (
        SELECT MAX(id)
        FROM [enter image description here][1]fundrecord
        GROUP BY memberId)
        )

请在查询中使用DISTINCT

UPDATE member
SET member.usableSum = (SELECT distinct usablesum
    FROM fundrecord
    WHERE (member.id= fundrecord.memberId) AND id IN (
    SELECT MAX(id)
    FROM [enter image description here][1]fundrecord
    GROUP BY memberId)
    )

如果您仍然面临同样的问题,那么您的子查询返回了多个值

我猜你想要:

UPDATE member m
    SET m.usableSum = (SELECT fr.usablesum
                       FROM fundrecord fr
                       WHERE m.id = fr.memberId
                       ORDER BY fr.id DESC
                       LIMIT 1
                      );

此 returns 来自 fundrecord 的 "most recent" usablesum 每个成员。