0

从下表中,编写查询以获取已完成手术但从未开过任何处方的独特医师的专业直方图。

病人治疗台

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

事件类别表

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

医师专业表

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

样本输出:

specialty speciality_count
Oncologist 2
Radiologist 1

我使用的数据库是 Mysql

4

1 回答 1

1

我把这个小提琴放在一起: 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 并计算剩余的专业。

于 2021-04-23T19:55:27.710 回答