结果应该是:
Doctors_have_no_patients
Doctor2
Doctor3
Doctor5
表
Doctor table called `Doctors`
**DoctorID**
Doctor1
Doctor2
Doctor3
Doctor4
Doctor5
Booking table called `Bookings`
PatientID DoctorID Date
Patient1 Doctor1 etc.
Patient2 Doctor4 etc.
Patient3 Doctor1 etc.
我应该使用distinct
还是其他什么?类似:
select Bookings.DoctorID as Doctors_have_no_patients count(distinct(Bookings.PatientID))...
您可以在中使用not(在这种情况下也没有区别)
没有病人的医生数量
select count(*) from Doctors
where DoctorId not in (select doctorID from bookings);
医生Id
select DoctorID from Doctors
where DoctorId not in ( select doctorID from bookings);
使用以下查询
SELECT * from `Doctors`
WHERE `DoctorID` NOT IN (SELECT DISTINCT(`doctorID`) FROM `bookings`);