2017-05-22 72 views
-1

我必須使用MySQL查詢:如何使用 「其中查詢」 CakePHP的3.X

SELECT doctor_id FROM `appointments`where doctor_id in (SELECT doctor_id FROM doctor_staffs WHERE staff_id=11) 

結果:

doctor_id 
2 
4 
5 

,但我需要知道如何把它寫在CakePHP 3中

+0

可能的重複[CakePHP 3中的子查詢?](http:// stackov erflow.com/questions/33884603/subqueries-in-cakephp-3) – drmonkeyninja

回答

-1
$this->loadModel('DoctorStaffs'); 
    $docTorStaff=$this->DoctorStaffs->find()->select(['doctor_id'])->where(['staff_id'=>11]); 
    $this->loadModel('Appointments'); 
    $appointments = $this->Appointments->find(); 
    $appointments=$appointments->where(['Appointments.doctor_id IN'=>$docTorStaff]);