将MySQL查询转换为Laravel生成器4.2


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

你应该试试这个

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

相关内容

  • 没有找到相关文章

最新更新