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();
答案 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();