从下表中,编写查询以获取完成该程序的唯一医生的专业直方图

From the following tables, write a query to get the histogram of specialties of the unique physicians who have done the procedures

在接下来的 table 中,编写查询以获取已完成手术但从未开过任何处方的唯一医生的专业直方图。

患者治疗table

Patient Id | Event Name | Physician ID
1 Radiation 1000
2 Chemotherapy 2000
1 Biopsy 1000
3 Immunosuppressants 2000
4 BTKI 3000
5 Radiation 4000
4 Chemotherapy 2000
1 Biopsy 5000
6 Chemotherapy 6000

事件类别table

Event Name | Category
Chemotherapy Procedure
Radiation Procedure
Immunosuppressants Prescription
BTKI Prescription
Biopsy Test

医师专业Table

Physician Id | specialty
1000 Radiologist
2000 Oncologist
3000 Hematologist
4000 Oncologist
5000 Pathologist
6000 Oncologist

示例输出:

specialty speciality_count
Oncologist 2
Radiologist 1

我使用的数据库是Mysql

我把这个 Fiddle 放在一起:http://sqlfiddle.com/#!9/2481c3/4/0

此查询是否找到您要查找的内容?

select specialty, count(*) specialty_count from pst
where physician_id not in 
 (select physician_id from ptt where event_name in 
  (select event_name from ect where category='prescription'))
and physician_id in
 (select physician_id from ptt where event_name in 
  (select event_name from ect where category='procedure'))
group by specialty

它正在使用子查询来过滤医生 ID 并计算剩余的专业。