Is there any way to convert following query to laravel query builder?
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
Is there any way to convert following query to laravel query builder?
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
Try as below :
$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();
employee_id,DB::raw("distinct as as from otc_employee_qualifications where emp_qualifctn_type in (27, 29) group by employee_id having counter = 2)->select('employee_id,DB::raw("distinct emp_qualifctn_type as counter')) into ->select('employee_id',DB::raw("distinct emp_qualifctn_type as counter"))otc_employee_qualifications where ' at line 1 (SQL: select employee_id, distinct emp_qualifctn_type as counter from otc_employee_qualifications where emp_qualifctn_type in (27, 29) group by employee_id having emp_qualifctn_type = 2)having clauseAnswer:
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();
You can convert SQL query into laravel eloquent query by using bellow website.
This will convert SQL query to laravel eloquent base query
officer_availabilities where officer_id = 52 and 1 BETWEEN start_day AND end_day"