mercredi 18 juillet 2018

Get sum() in two collumns in Laravel 5.4

Hi I have this table (Pickups) ,

+-----------+------------+-------------+------------+
| worker_id | box_weight | bag_weight |    date    |
+-----------+------------+-------------+------------+
|         1 |          2 |           5 | 11-07-2018 |
|         1 |          7 |           9 | 11-07-2018 |
|         2 |          8 |          11 | 11-07-2018 |
|         2 |          7 |          12 | 11-07-2018 |
+-----------+------------+-------------+------------+

and I want in Laravel 5.4 get the sum of the box_weight and the bag_weight like this:

+-----------+-----------------+-----------------+------------+
| worker_id | sum(box_weight) | sum(bag_weight) |    date    |
+-----------+-----------------+-----------------+------------+
|         1 |               9 |              14 | 11-07-2018 |
|         2 |              15 |              23 | 11-07-2018 |
+-----------+-----------------+-----------------+------------+

Until now I could only retrieve the sum of a single column not the both in the same call.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire