$oHospitals = DB::table("user_hospital")->leftjoin('ad_hospital_special','ad_hospital_special.hos_id', '=', 'user_hospital.id')
->selectRaw(' (IFNULL(`job_num`,0) + jobcount) as num,ad_hospital_special.hos_approve, user_hospital.*,job_num')
->orderBy('num')->get();
中的求和排序 (IFNULL(job_num
,0) + jobcount) as num
因为两个表联立,有的表没有job_num这个数据,会默认为NULL,表中类型为int,
NULL+int = NULL,所以需要转变NULL的字段为0,才可以进行加法运算
select (IFNULL(`job_num`,0) + IFNULL(`job_count`,0)) as sumres from table;