php - 如何统计没有患者预约的医生?

标签 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   Doctor4   etc.
Patient3   Doctor1   etc.

我应该使用 distinct或者其他的东西?喜欢:

select Bookings.DoctorID as Doctors_have_no_patients count(distinct(Bookings.PatientID))...

最佳答案

您可以使用 not in (在本例中也可以使用 not unique)

没有病人的医生数量

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);

关于php - 如何统计没有患者预约的医生?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37171529/

相关文章:

php - 在 HTML 中显示 XML

php - 如果我需要为其他表获取主 ID,如何插入

mysql - "almost"重复条目的 SQL 查询(最后 3 列的值相同)

javascript - 使用 PHP 将 Javascript 时间转换为 MySQL 格式

mysql - 如何从 MySQL 表中获取所有评论

php - 选择计数 php/sql

PHP在html表格的新行中显示下一个结果

php - 从 HTML 表单发送变量

mysql - 您如何对具有数学顺序的数字的字段进行排序

r - 计算模式并区分它们