我怎样才能从我的投票中获得最大数量的投票图片 table

how can i get the max count voted pictures from my vote table

SELECT userfbimages_id, count( * )
FROM votes
GROUP BY userfbimages_id 
HAVING count( * ) >= ALL (SELECT count( * )
                          FROM votes
                          GROUP BY userfbimages_id)

我尝试了这个查询,但我不知道如何在 laravel5.2 中进行!! 我试过了

$topim=Vote::where(SELECT userfbimages_id, count() FROM votes GROUP BY userfbimages_id HAVING count() >= ALL (SELECT count(*) FROM votes GROUP BY userfbimages_id));

returns 空

你错过了星星。

count(*) 应该是使该查询有效所需的全部!

对于那些为我的问题寻找答案的人,我找到了解决方案`

>     return $this->model
>                       ->where('seen','=', 1)
>                       ->with('votes')
>                       -sortby(function($top){
>                       return $top->votes->count();}, SORT_REGULAR, true);

this works with sortby and with a subquery !! but for a pagination you should change this with lefjoin statement :

                return $this->model
                    ->where('seen','=', 1)
                    ->leftJoin('votes','votes.userfbimages_id','=','userfbimages.id')
                    ->selectRaw('userfbimages.*, count(votes.userfbimages_id) AS `count`')
                    ->groupBy('userfbimages.id')
                    ->orderBy('count','DESC')
                    ->paginate($n);
`

我找到了解决方案,希望对您有所帮助