Php 如何统计没有病人预约的医生?
结果应该如下所示:Php 如何统计没有病人预约的医生?,php,mysql,count,Php,Mysql,Count,结果应该如下所示: 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 Doctor
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
还是什么?比如:
选择Bookings.DoctorID作为医生\u没有\u患者计数(distinct(Bookings.PatientID))…
您可以在中使用not(在这种情况下没有distinct)
没有病人的医生人数
select count(*) from Doctors
where DoctorId not in (select doctorID from bookings);
医生身份证
select DoctorID from Doctors
where DoctorId not in ( select doctorID from bookings);
您可以在中使用not(在本例中使用not distinct)
没有病人的医生人数
select count(*) from Doctors
where DoctorId not in (select doctorID from bookings);
医生身份证
select DoctorID from Doctors
where DoctorId not in ( select doctorID from bookings);
使用以下查询
SELECT * from `Doctors`
WHERE `DoctorID` NOT IN (SELECT DISTINCT(`doctorID`) FROM `bookings`);
使用以下查询
SELECT * from `Doctors`
WHERE `DoctorID` NOT IN (SELECT DISTINCT(`doctorID`) FROM `bookings`);
你需要养成帮助你解决问题的习惯。您将获得积分,并鼓励其他人帮助您。您需要在
预订中使用distinct
,
边写边选择@tews您需要养成帮助您解决问题的习惯。您将获得积分,并鼓励其他人帮助您。您需要在预订中使用distinct
,
在您编写@tews时选择为什么OP“使用以下内容”?一个好的答案总是会有一个解释,说明做了什么以及为什么这样做,不仅是为了OP,而且是为了未来的访客。OP为什么要“使用以下内容”?一个好的答案总是会有一个解释,说明做了什么以及为什么这样做,不仅是为了OP,而且是为了未来的访客。