如何基于laravel查询构建器

时间:2016-04-23 11:43:30

标签: php mysql laravel-5.2

我想转换支持laravel查询构建器的以下查询

select specialization_master.sm_specializationtype from 
specialization_master 
join hospital_profile_master on FIND_IN_SET(specialization_master.sm_id ,  (select hospital_profile_master.hp_specialization from hospital_profile_master where hp_hospitalid = 'HOS10011'))
group by specialization_master.sm_specializationtype

我写的如下

$query_filter_dept_list = DB::table('specialization_master')
                            ->join('hospital_profile_master',DB::raw(FIND_IN_SET(specialization_master.sm_id , (select hospital_profile_master.hp_specialization from hospital_profile_master where hp_hospitalid = $hospital_id))))
                            ->select('specialization_master.sm_specializationtype')
                            ->groupBy('specialization_master.sm_specializationtype')
                            ->get();

但它在ReceptionistController.php第35行显示错误 FatalErrorException:语法错误,意外的'hospital_profile_master'(T_STRING)

1 个答案:

答案 0 :(得分:0)

是的,最后我用/ DB :: select();解决问题及其工作正常的方法。