如何以 Laravel 方式执行此连接查询?
How to do this join query in Laravel way?
select tb_addquestion.UserId, COUNT(*) AS count from `tb_addquestion`
left join `tb_user` on `tb_user`.`UserId` = `tb_addquestion`.`UserId`
GROUP BY(tb_addquestion.UserId) having count > 0 AND count < 15
DB::table('tb_addquestion')
->leftJoin('tb_user', 'tb_user.UserId', 'tb_addquestion.UserId')
->groupBy('tb_addquestion.UserId')
->having('count', '>', 0)
->having('count', '<', 15)
->select('tb_addquestion.UserId', DB::raw('COUNT(*) AS count'));
select tb_addquestion.UserId, COUNT(*) AS count from `tb_addquestion`
left join `tb_user` on `tb_user`.`UserId` = `tb_addquestion`.`UserId`
GROUP BY(tb_addquestion.UserId) having count > 0 AND count < 15
DB::table('tb_addquestion')
->leftJoin('tb_user', 'tb_user.UserId', 'tb_addquestion.UserId')
->groupBy('tb_addquestion.UserId')
->having('count', '>', 0)
->having('count', '<', 15)
->select('tb_addquestion.UserId', DB::raw('COUNT(*) AS count'));