Thursday, March 2, 2017

Laravel Sum column database Eloquent

Trying to get the sum of a int field in one of my table should be pretty easy, unfortunately it is not as I'm getting different result whether I use Laravel, MySQL or Excel.

Laravel 5.4 gives me 20506:

Table::sum('field_name');

MySQL gives me 1830:

Select sum(field_name) from table;

And the data from the Excel sheet before importing it into the database: Sum gives me 145689

Any idea? I tried to cast to integer before doing the sum but it doesn't work. All the numbers are pretty big but don't contain comma or dot.

Examples of values I have to sum: (contain sometimes empty cells)

17906774
99630157
28581131

159551532
20312892
668928885



via Andrew

Advertisement