1
내가 쿼리 빌더 laravel이 SQL을 할 수있는 방법내가 쿼리 빌더 laravel이 SQL을 수행 할 수있는 방법
select Doctor_id from doctors where Doctor_id NOT IN
(SELECT Doctor_id from report_reviewers WHERE Report_id = 26)
내가 쿼리 빌더 laravel이 SQL을 할 수있는 방법내가 쿼리 빌더 laravel이 SQL을 수행 할 수있는 방법
select Doctor_id from doctors where Doctor_id NOT IN
(SELECT Doctor_id from report_reviewers WHERE Report_id = 26)
이
$result = DB::table('doctors')
->whereNotIn('doctor_id', function($q){
$q->from('report_reviewers')
->select('Doctor_id')
->where('Report_id', '=', 26)
})
->select('doctor_id')
->get();
Whenver 의심과 시도 , 당신은 단순히 또한
$query = 'select Doctor_id from doctors ...';
$result = DB::select($query);
을 할 수있는 모든 신용이 천재 How to create a subquery using Laravel Eloquent?
로 이동 당신이->whereNotIn('doctor_id', function($q,$id){
$q->from('report_reviewers')
->select('Doctor_id')
->where('Report_id',$id);
})
당신은 다시 시도하고 볼이
->whereNotIn('doctor_id', function($q) use ($id) {
$q->from('report_reviewers')
->select('Doctor_id')
->where('Report_id',$id);
})
처럼 $id
변수를 전달해야 사용
업데이트
누락 된 인수는 폐쇄에서 비롯됩니다.
효과가 있습니다. 감사! –
어떨까요 : $ result = DB :: table ('의사') -> ('사용자', '의사'사용자 ID ','= ','users.id ') -> ('report_reviewers') -> select ('Doctor_id') -> 여기서 '(') '(허용되는') 1, -> 여기서 ' ('doctors.doctor_id', '사용자 이름') -> get(); 인수 2 ($ id)에 누락되었습니다 –
시도해 보셨습니까? 오류는 무엇입니까? – EddyTheDove