通过IP&获得最重复的帐户机器的用户名?

时间:2017-07-31 18:00:42

标签: php mysql laravel

我想知道为什么这段代码不起作用,但首先我会解释我想要尝试做的事情。我必须在表格中创建前10个用户名列表#34;用户"具有克隆最多的帐户(IP克隆+机器克隆),然后显示他们通过IP获得的克隆数量,以及他们通过机器获得的克隆数量。

当我说克隆时,我指的是同一列ip_last和列machine_id,以便它可以由同一个ip或同一台机器创建。

我在Laravel写这个,我先尝试了下面的代码:

$cloneList = DB::table("users")
        ->select("username", DB::raw("COUNT(*) AS `cloned`"))
        ->whereIn("ip_last", function ($query) {
            $query->select("ip_last")
                ->from("users")
                ->groupBy("ip_last")
                ->havingRaw("COUNT(*) > 1");
        })
        ->orWhereIn("machine_id", function ($query) {
            $query->select("machine_id")
                ->from("users")
                ->groupBy("machine_id")
                ->havingRaw("COUNT(*) > 1");
        })
        ->orderBy("cloned", "DESC")
        ->limit(20)->get();

我遇到的错误:

(1/2) PDOException
SQLSTATE[42000]: Syntax error or access violation: 1140 Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause

(2/2) QueryException
SQLSTATE[42000]: Syntax error or access violation: 1140 Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause (SQL: select `username`, COUNT(*) AS `cloned` from `users` where `ip_last` in (select `ip_last` from `users` group by `ip_last` having COUNT(*) > 1) or `machine_id` in (select `machine_id` from `users` group by `machine_id` having COUNT(*) > 1) order by `cloned` desc limit 20)

那么我想做什么呢?这样的事情: 前4个克隆

Username: Elvis-Presley
Clones (Total): 12
Clones (IP): 3
Clones (Machine): 9

Username: Elvis-Presley
Clones (Total): 12
Clones (IP): 3
Clones (Machine): 9

Username: Elvis-Presley
Clones (Total): 12
Clones (IP): 3
Clones (Machine): 9

Username: Elvis-Presley
Clones (Total): 12
Clones (IP): 3
Clones (Machine): 9

我只保留了4个而且只是为了示例目的而显示,在实际代码中它按照他们拥有的总克隆顺序显示,显示最多的cloney用户。

有谁知道我为什么遇到这个问题?我不确定我为什么,我已经接受了另一个问题的答案,但它似乎没有用?

0 个答案:

没有答案
相关问题