Reputation: 139
I'm trying to count all the elements of a column with Query Builder and I can't exclude null values from the count, I tried this code but it didn't work.
$ttg = DB::table('incidencias')
->select(DB::raw('count(*) as ttg, inc_padre'))
->where('inc_padre', '<>', null)
->groupBy('inc_padre ')
->get();
Thanks in advance!
Upvotes: 0
Views: 1154
Reputation: 8618
Try this one
$ttg = DB::table('incidencias')
->select(DB::raw('count(*) as ttg, inc_padre'))
->whereNotNull('inc_padre')
->groupBy('inc_padre')
->get();
For find all counts where inc_padre is not null
$ttg = DB::table('incidencias')
->whereNotNull('inc_padre')
->count();
Upvotes: 2