选择存储位置,最大(current_6kg)opbal6kg,最大(current_13kg)opbal13kg,最大(current_burner)opbalBurners,最大(current_grill)opbalGrills,最大(current_50kg)opbal50kg,max(Loaded6KG)in_6kg,max(Loaded13KG)in_13最大(已装载50KG)in_50kg,最大(燃烧器)in_burners,最大(烧烤)in_grills,总和(未售出6KG)未售出6KG,总和(未售出13KG)未售出13KG,总和(未售出50KG)未售出50KG,总和(未出6kg)总出(6kg,总和(未出13kg) out_50kg)out_50kg,从tbl_current_stocks_filled cu左外部联接中求和(out_burners)out_burners,sum(out_grills)out_grills(从tblStockTransfer选择*,其中cast(DateTransferred as date)= cast(getdate()as date))t on t.destination = cu .storage_location左外部联接(选择分配的位置,总和(op_bal_6KG + Loaded6KG)out_6kg,总和(op_bal_13KG + Loaded13KG)out_13kg,总和(op_bal_50KG + Loaded50KG)out_50kg,总和(op_bal_grills + Grills)out_grills,总计(op_balburns) l内部联接tblUsers u在l.UserID = u.UserID上,其中cast(l.DateLoaded as date)= cast(ge将tdate()作为日期)按AssignedLocation分组)y.assignedLocation = cu.storage_location上的y左外部联接(从Untold6KG,Unsold13KG,Unsold50KG,UnsoldBurners,UnsoldGrills,tLocation从tblTruckUnLoading l左分配外部联接tblUsers在u.UserID = l上选择。在x.assignedLocation = cu.storage_location上x的用户ID,其中cast(l.DateOffLoaded为日期)= cast(getdate()为日期) 按cu.storage_location分组
答案 0 :(得分:0)
您可以使用文档中的DB::raw
方法:https://laravel.com/docs/5.4/queries#raw-expressions
$results = DB::select( DB::raw("select cu.storage_location,max(current_6kg)opbal6kg,max(current_13kg)opbal13kg, max(current_burner)opbalBurners,max(current_grill)opbalGrills, max(current_50kg)opbal50kg,max(Loaded6KG)in_6kg,max(Loaded13KG)in_13kg,max(Loaded50KG)in_50kg, max(burners)in_burners,max(grills)in_grills ,sum(Unsold6KG)Unsold6KG,sum(Unsold13KG)Unsold13KG,sum(Unsold50KG)Unsold50KG, sum(out_6kg)out_6kg,sum(out_13kg)out_13kg,sum(out_50kg)out_50kg, sum(out_burners)out_burners,sum(out_grills)out_grills from tbl_current_stocks_filled cu left outer join( select * from tblStockTransfer where cast(DateTransferred as date)= cast(getdate() as date)) t on t.destination =cu.storage_location left outer join ( select assignedLocation, sum (op_bal_6KG+Loaded6KG)out_6kg,sum(op_bal_13KG+Loaded13KG)out_13kg, sum(op_bal_50KG+Loaded50KG)out_50kg ,sum(op_bal_grills+Grills)out_grills, sum(op_bal_burners+Burners)out_burners from tblTruckLoading l inner join tblUsers u on l.UserID=u.UserID where cast(l.DateLoaded as date)= cast(getdate() as date) group by assignedLocation ) y on y.assignedLocation=cu.storage_location left outer join ( select Unsold6KG,Unsold13KG,Unsold50KG,UnsoldBurners,UnsoldGrills, assignedLocation from tblTruckUnLoading l left outer join tblUsers u on u.UserID=l.UserID where cast(l.DateOffLoaded as date)= cast(getdate() as date) )x on x.assignedLocation=cu.storage_location group by cu.storage_location") );