laravel原始查询连接两个表并使用SUM函数

时间:2018-08-29 22:36:13

标签: mysql sql laravel

所以我必须表一表和表二,这是我的查询

EitherT

我看到一条错误消息 $result = DB::table('table_1') ->select('table_1.id', 'table_1.sys_id', 'table_1.cam_name', 'table_1.description', 'table_1.brand', 'table_1.product', 'table_1.status', 'table_1.updated_by', 'table_1.start_date', 'table_1.end_date', DB::raw ("DATE_FORMAT(CONVERT_TZ(table_1.created_at, @@session.time_zone, '" . Common::utc_offset() ."'),'%Y-%m-%d %H:%i:%s') as created_at"), DB::raw("DATE_FORMAT(CONVERT_TZ(table_1.updated_at, @@session.time_zone, '" . Common::utc_offset() . "'), '%Y-%m-%d %H:%i:%s') as updated_at"),'hashid', 'alm_fields', 'inactive_period', 'test', 'signature','camp_type', 'SUM(IF(table_2.inter= 1 AND table_2.admin_resp= 0, 1, 0)) as hi_count') ->leftJoin('table_2', 'camp.id', '=', 'table_2.fk_camp_id') ->GroupBy('table_1.id') ->paginate(10);

0 个答案:

没有答案