3 回答
TA贡献1817条经验 获得超14个赞
这在 Laravel 中处理起来很棘手。您的WHERE子句中的逻辑基本上是(A and B) or C,其中条件A可以由NOT EXISTSMySQL 中的子查询表示。
$drivers = DB::table('Driver d')
->where(function($query1) {
return $query1
->whereNotExists(function ($query2) {
$query2->select(DB::raw(1))
->from('buses b')
->whereRaw('d.driver_number = b.driver_number');
})
->where('station_id', '=', '2');
})
->orWhere('driver_number', '=', 'Dr_02');
->get();
TA贡献1858条经验 获得超8个赞
您可以尝试使用
$task_without_due_date = \DB::select(\DB::raw("SELECT * FROM drivers where driver_number NOT IN (SELECT driver_number FROM buses) AND station_id = '.$station_id.' OR driver_number = '.$bus->Driver_id.'"));
TA贡献1843条经验 获得超7个赞
试试这个,
$result = DB::table('drivers')
->whereNotIn('driver_number', function($q){
$q->select('driver_number')->from('buses');
})
->where('station_id', '=', 2)
->where('driver_number', '=', 'Dr_02')
->get();
- 3 回答
- 0 关注
- 138 浏览
添加回答
举报