php - Sum multiple fields in 1 table
438
Hi I would like to sum my 4 columns in my table.
but I get errorhe SUM function requires 1 argument(s)
itemcost table
+------+------+------+------+------+
| id | col1 | col2 | col3 | col4 |
+======+======+======+======+======+
| 0002 | 5 | 5 | 5 | 5 |
+------+------+------+------+------+
| | | | | |
+------+------+------+------+------+
| | | | | |
+------+------+------+------+------+
$cost= DB::table('itemcost')
->select(
DB::raw('SUM(col1,col2,col3,col4) as unitprice')
);
Thank you in advance.
Answer
Solution:
To sum just column of every single row, use:
Or, to sum columns with rows, use:
By the way, here is an article with examples
Answer
Solution:
You could add columns with + sign, Try like bellow: