有没有办法将以下查询转换为laravel查询构建器?
select `employee_id`
from `otc_employee_qualifications`
where `emp_qualifctn_type` IN ('29','27')
group by `employee_id`
having count(Distinct `emp_qualifctn_type`) = 2
答案 0 :(得分:2)
尝试如下:
$users = DB::table('otc_employee_qualifications')
->select('employee_id')
->whereIn('emp_qualifctn_type', [27,29])
->groupBy('employee_id')
->having(DB::raw("count(Distinct emp_qualifctn_type)"), '=', 2)
->get();
答案 1 :(得分:-1)
答案:
DB::select('employee_id')
->from('otc_employee_qualifications')
->whereIn('emp_qualifctn_type', ('29', '27'))
->groupBy('employee_id')
->having(DB::raw('count(Distinct emp_qualifctn_type)'), '=', 2)
->get();
您可以使用下面的网站将SQL查询转换为laravel eloquent查询。
这会将SQL查询转换为laravel eloquent base query