我试图删除所有与我的mybb数据库中使用了两次以上的ips相关联的帐户。下面的代码可以“选择”这些用户。

SELECT * FROM `mybb_forumusers` WHERE `regip` IN (
    SELECT `regip` FROM `mybb_forumusers`
    GROUP BY `regip`
    HAVING COUNT( `regip` ) > 2
)

但是,如果没有错误,我无法成功删除所有这些用户。我尝试过以下(和变体):
DELETE FROM `mybb_forumusers` WHERE `uid` IN (
    SELECT `uid` FROM `mybb_forumusers` WHERE `regip`IN (
        SELECT `regip` FROM `mybb_forumusers`
        GROUP BY `regip`
        HAVING COUNT( `regip` ) > 2
    )
)

最佳答案

我建议使用join

DELETE fu
    FROM `mybb_forumusers` fu JOIN
         (SELECT `regip`
          FROM `mybb_forumusers`
          GROUP BY `regip`
          HAVING COUNT( `regip` ) > 2
         ) fu2
         ON fu2.regip = fu.regip;

10-05 19:39