vendredi 11 octobre 2019

Laravel combining two tables and calculating values from one of them

I have two tables in the database: counters and counter history. I would like to receive a table with counters and for each counter, from the table 'countershistory' subtracting the first and last value from the 'value' column and pass it to the counters as counterhistory_value. Here is the code I currently have

$counters= Counter::all()
->select('countershistory.value as counterhistory_value')
->join('countershistory', 'countershistory.counter_id', '=', 'counter.id')
->groupBy('id')
->get();

Thanks for help.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire