如何在laravel控制器中使用此脚本?
SELECT MAX(branch_tbl.branch_name) AS Branch_Name, COUNT(staffinfo.branchID) AS Count_Branch
FROM branch_tbl
LEFT JOIN staffinfo ON staffinfo.branchID = branch_tbl.branch_id
GROUP BY branch_tbl.branch_id;
答案 0 :(得分:2)
你可以使用它
DB::table('branch_tbl')->select(DB::raw('MAX(branch_tbl.branch_name) AS Branch_Name, COUNT(branch_tbl.branch_id) AS Count_Branch'))
->leftJoin('staffinfo', 'staffinfo.branchID', '=', 'branch_tbl.branch_id')
->groupBy('branch_tbl.branch_id')->get()