Home > Software engineering >  How to get top 3 sum of the table based on level in Laravel
How to get top 3 sum of the table based on level in Laravel

Time:08-16

I have table like this

enter image description here

i want to sum to get Total Team Score based on level and top 3 score based on score 1, score 2, score 3

TOTAL SCORE TEAM = Top3 Score 1 Top3 Score 2 Top3 Score 3

Result i hope

enter image description here

Can anyone help me how to get the result in my controller and my blade?

CodePudding user response:

You should add Total score colum in your first colum then use this command to use this command to find whose score is highest level wise $result=[]; for($k =0; $k<3 ;$k ) $result[$k]=Cliente::max('total_score')->where('level', $k)

CodePudding user response:

I test this example it's successful

$data = DB::table('group_table')
    ->select('team','level',DB::raw('sum(score1   score2   score3) as total'))
    ->groupBy('team','level')
    ->get();

return response()->json($data);

DB

enter image description here

Result

enter image description here

  • Related