2

我收到:

[Err] 1235 - This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'

在执行以下查询时:

UPDATE account.account
SET STATUS = 'BLOCK'
WHERE
    id IN (
        SELECT
            p.account_id
        FROM
            log.log
        LEFT JOIN player.player p ON (p.id = log.who)
        WHERE
            vnum = 71054
        AND how = 'BUY'
        GROUP BY
            log.`who`
        HAVING
            COUNT(log.who) > 2
        LIMIT 10
    );

是否有可能重写此查询以便 MySQL 可以执行它?

4

1 回答 1

4

解决方案是加入子查询而不是使用IN(). INNER JOIN只会account从有限的子查询中返回匹配 id 的行。然后可以在UPDATE没有WHERE子句的情况下进行。

Update 
  account.account AS account
  INNER JOIN (
        SELECT
            p.account_id
        FROM
            log.log
            LEFT JOIN player.player p ON (p.id = log.who)
        WHERE
            vnum = 71054
            AND how = 'BUY'
        GROUP BY log.`who`
        HAVING COUNT(log.who) > 2
        LIMIT 10 
   ) subq ON account.id = subq.id
SET STATUS='BLOCK'

要验证将被修改的行,请使用SELECT第一个:

SELECT
  account.*
FROM 
  account.account
  INNER JOIN (
            SELECT
                p.account_id
            FROM
                log.log
                LEFT JOIN player.player p ON (p.id = log.who)
            WHERE
                vnum = 71054
                AND how = 'BUY'
            GROUP BY log.`who`
            HAVING COUNT(log.who) > 2
            LIMIT 10 
       ) subq ON account.id = subq.id
于 2012-09-29T20:56:09.267 回答