将mysql查询转换为laravel builder 4.2

时间:2018-05-30 06:30:15

标签: laravel-4

SELECT user_id, email, username, password, COUNT(*) AS count
FROM users
where email = 'dyz@dss.com'
GROUP BY password HAVING count > 0
ORDER BY count DESC;

我试过以下代码不起作用请提前指导如何做到这一点

User::SELECT('user_id, email, username, password, COUNT(*) AS count')
                                    ->where('email', Input::get('username'))
                                    ->groupBy('password')
                                    ->havingRaw('count > 0')
                                    ->orderBy('count', 'DESC')
                                    ->get();

1 个答案:

答案 0 :(得分:0)

你应该试试这个

DB::table('users')
                                     ->select(DB::raw('count(*) as count, user_id, email, username, password'))
                                    ->where('email', Input::get('username'))
                                    ->orderBy('count', 'DESC')
                                    ->groupBy('password')
                                    ->having('count', '>', 0)
                                    ->get();