vendredi 10 avril 2020

Get maximum values in column with diferents foreign ids in Laravel

I want to get the largest value from a column, but those values ​​correspond to two different foreign ids, so I want it to return the maximum number for each foreign id. I don't know If I have to use max()... At the moment I am just using groupBy with the two foreign ids.

Here the table in MySqlAdmin. I want to get the maximum bid for each id_group and id_karatekas: enter image description here

And here is my code:

public function soldKarateka()
    {
        $response = array('code' => 400, 'error_msg' => []);
       self::getBidByKaratekaGroup($response);
       return response($response, $response['code']);
    }


    private function getBidByKaratekaGroup( & $response){
        $bidsPerKarateka = DB::table('bids')
            ->groupBy('id_group','id_karatekas')
           ->get();
             $response = array('code' => 200, 'Karatekas order by group' => $bidsPerKarateka);
    }


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire