如何计数忽略空值的列的元素在Laravel 6.0中
我正在尝试使用查询生成器计算列的所有元素,但不能排除空值从计数上看,我尝试了这个代码,但没有成功如何计数忽略空值的列的元素在Laravel 6.0中,laravel,Laravel,我正在尝试使用查询生成器计算列的所有元素,但不能排除空值从计数上看,我尝试了这个代码,但没有成功 $ttg = DB::table('incidencias') ->select(DB::raw('count(*) as ttg, inc_padre')) ->where('inc_padre', '<>', null) ->groupBy('inc_padre
$ttg = DB::table('incidencias')
->select(DB::raw('count(*) as ttg, inc_padre'))
->where('inc_padre', '<>', null)
->groupBy('inc_padre ')
->get();
提前谢谢 试试这个
$ttg = DB::table('incidencias')
->select(DB::raw('count(*) as ttg, inc_padre'))
->whereNotNull('inc_padre')
->groupBy('inc_padre')
->get();
用于查找inc_padre不为空的所有计数
$ttg = DB::table('incidencias')
->whereNotNull('inc_padre')
->count();
试试这个
$ttg = DB::table('incidencias')
->select(DB::raw('count(*) as ttg, inc_padre'))
->whereNotNull('inc_padre')
->groupBy('inc_padre')
->get();
用于查找inc_padre不为空的所有计数
$ttg = DB::table('incidencias')
->whereNotNull('inc_padre')
->count();
尝试->groupBy'inc_padre',deleted space inc_padre delete后面有一个空格。将inc_padre更改为此inc_padre。顺便说一句,虽然答案比你的好得多,但它仍然像你的代码那样。是的,我做了,但我想要一个带有计数的单个数字,其中NOTNULL为我提供了columnDB::table'incidencias'->where'inc_padre','!=',->选择Raw'CountDifferentics\u padre as count'->get;DB::表'incidencias'->其中'inc_padre','!=',->countDB::原始的'distinc_padre';尝试->groupBy'inc_padre',deleted space inc_padre delete后面有一个空格。将inc_padre更改为此inc_padre。顺便说一句,虽然答案比你的好得多,但它仍然像你的代码那样。是的,我做了,但我想要一个带有计数的单个数字,其中NOTNULL为我提供了columnDB::table'incidencias'->where'inc_padre','!=',->选择Raw'CountDifferentics\u padre as count'->get;DB::表'incidencias'->其中'inc_padre','!=',->countDB::原始的'distinc_padre';