Mysql ve为1(单身人数)。请原谅我的错误解释。@Komal按名称分组没有帮助,因为firstname和lastname也在同一字段中。我认为他需要把姓和名分开。 | id | person_id | name | +----+-------
Mysql ve为1(单身人数)。请原谅我的错误解释。@Komal按名称分组没有帮助,因为firstname和lastname也在同一字段中。我认为他需要把姓和名分开。 | id | person_id | name | +----+-------,mysql,laravel,Mysql,Laravel,ve为1(单身人数)。请原谅我的错误解释。@Komal按名称分组没有帮助,因为firstname和lastname也在同一字段中。我认为他需要把姓和名分开。 | id | person_id | name | +----+--------------+------------| | 1 | NULL | John Doe | +----+--------------+------------| | 2 | NULL
ve为1(单身人数)。请原谅我的错误解释。@Komal按名称分组没有帮助,因为firstname和lastname也在同一字段中。我认为他需要把姓和名分开。
| id | person_id | name |
+----+--------------+------------|
| 1 | NULL | John Doe |
+----+--------------+------------|
| 2 | NULL | Jane Doe |
+----+--------------+------------+
| 3 | 1 | Junior J.D.|
+----+--------------+------------+
| 4 | 1 | Senior J.D.|
+----+--------------+------------+
$query = DB::table('people')
->select(DB::raw('count(*) as count'))
->where('person_id', '=', NULL)
->get();
$query = DB::table('people')
->whereNull('person_id')
->whereIn('id', function($query) {
$query->select('person_id')
->from('people')
->whereNotNull('person_id');
}, 'and', TRUE)
->count();
$query = DB::table('people')
->whereNull('person_id')
->groupBy('name')
->count();
$query = DB::table('people')
->whereNull('person_id')
->groupBy('lastname')
->count();