【发布时间】:2015-04-29 02:22:18
【问题描述】:
RDMBS:甲骨文 嵌套查询是一项要求。
我正在尝试收集 2014 年 3 月预约的所有患者,并显示他们看过的医生以及诊断出的疾病。然后显示预约 ID、患者全名、年龄、性别和电话,并显示医生全名和电话。在我询问患者被诊断出患有什么疾病之前,我能够完成大部分工作。
此代码允许我访问 2014 年 3 月的患者和医生记录:
Select Appointment.appointmentid, patient.surname ||','|| patient.given as Patient, trunc(((sysdate-patient.dob)/365),0) as Patient_Age, patient.phonehome as Patient_Contact, doctor.Surname ||','|| doctor.given as Doctor, doctor.phone as Doctor_Contact
from doctor, patient, appointment
where doctor.doctorid=appointment.doctorid
and patient.patientid=appointment.patientid
and extract(month from dateofappointment) = '03'
and extract(year from dateofappointment) = '2014';
但是一旦我放入嵌套查询进行诊断,我就会得到错误。
代码:
Select Appointment.appointmentid, patient.surname ||','|| patient.given as Patient, trunc(((sysdate-patient.dob)/365),0) as Patient_Age, patient.phonehome as Patient_Contact, disease.name as Diagnosis, doctor.Surname ||','|| doctor.given as Doctor, doctor.phone as Doctor_Contact
from doctor, patient, appointment
where disease.name in (select disease.name
from disease
where disease.diseaseid=diagnosed.diseaseid
and diagnosed.appointmentid=appointment.appointmentid)
and doctor.doctorid=appointment.doctorid
and patient.patientid=appointment.patientid
and extract(month from dateofappointment) = '03'
and extract(year from dateofappointment) = '2014';
任何更正或建议将不胜感激。
【问题讨论】:
-
你遇到了什么错误?
-
第 3 行出现错误:ORA-00904:“疾病”。“名称”:标识符无效
标签: sql oracle join nested-queries