groupBY and extra parameter how

Posted 7 months ago by arctushar

Hi I am trying to get result as below

return $userInfo = DB::table('portfolios')->select('quantity', DB::raw('sum(quantity*buy) as buytotal'), DB::raw('sum(quantity*(Dsedata::where('codelist_id',codelist_id)->first()->ltp)) as selltotal'),'codelist_id')->groupBy('codelist_id') ->get(); 

this is giving error but when I m using below query, its works fine

return $userInfo = DB::table('portfolios')->select('quantity', DB::raw('sum(quantity*buy) as buytotal'), DB::raw('sum(quantity*codelist_id) as selltotal'),'codelist_id')->groupBy('codelist_id') ->get();

How can I make query as first code given above?

plz help

Please sign in or create an account to participate in this conversation.