如何将 mysql 查询转换为 laravel 查询生成器
How to convert mysql query to laravel query builder
是否有任何方法可以将以下查询转换为 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
尝试如下:
$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();
答案:
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 基本查询
是否有任何方法可以将以下查询转换为 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
尝试如下:
$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();
答案:
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 基本查询