有没有办法可以更好地写出来?它当前编写的方式需要很长时间来提取数据。数据的结果也重复数据具有相同信息的多行。有什么建议?我尝试更改了join子句,但这并没有多大帮助。我不知道还能用什么来缩短查询,使其运行更顺畅,并获得更好的结果。
select
PT_IDENTIFIER.PT_IDENTIFIER_VALUE,
PT_STUDY.FK_SOCRD_ID,
patient.PTLASTNAME || ', ' || patient.PTFIRSTNAME as "Patient name",
patient.DOB,
PT_STUDY.SUBJECT_NUMBER,
CR_imaging.CR_IMAGING as "CR_Imaging",
CR_imaging.CR_IMAGING_SPEC,
CR_IMAGING.CR_IMAGING_DT,
CR_imaging.CR_IMG_SITE,
CR_IMAGING.CR_IMG_SITE_SPEC,
CR_IMAGING.CR_IMAGING_CT,
CR_IMAGING.CR_IMAGING_CN,
CR_IMAGING.CR_IMAGING_CM,
CR_WORKUPPROC.CR_WORKUPPROC,
CR_WORKUPPROC.CR_WORKUPPROC_DT,
CR_DISEASE_HISTORY.CR_DISEASE_HISTORY,
CR_DISEASE_HISTORY.CR_DISEASE_HISTORY_DT,
CR_MDT.CR_MDT_DT,
CR_MDT.CR_MDT_DIAG,
CR_MDT.CR_MDT_PHYS,
CR_MDT.CR_MDT_PRESENTED,
CR_MDT.CR_MDT_HISTTYPE,
CR_MDT.CR_MDT_STAGE,
CR_MDT.CR_MDT_CT,
CR_MDT.CR_MDT_CN,
CR_MDT.CR_MDT_CM,
CR_MDT.CR_MDT_PT,
CR_MDT.CR_MDT_PN,
CR_MDT.CR_MDT_PM,
CR_MDT.CR_MDT_LOOKBACK,
CR_MDT_PATH_REVIEW_DT,
CR_MDT_PATH_REVIEW,
CR_MDT_RECOM.CR_MDT_RECOM,
CR_MDT_RECOM.CR_MDT_RECOM_SPEC,
TUMORSITE.DIAGNOSIS_DT,
TUMORSITE.TUMORSITE,
TUMORSITE.TUMORSITE_SPEC,
TUMORSITE.RECURRENCE_DT,
TUMORSITE.RECURRENCE_DT_EST,
TUMORSITE.METASTASIS_DT,
TUMORSITE.METASTASIS_DT_EST,
CR_SYSTEMIC.CR_AGENT,
CR_SYSTEMIC.CR_AGENT_SPEC,
CR_SYSTEMIC.CR_SYS_CYCLE,
CR_SYSTEMIC.CR_SYS_DOSE_DAY,
CR_SYSTEMIC.CR_SYS_DOSE_TOTAL,
CR_SYSTEMIC.CR_SYS_START_DT,
CR_SYSTEMIC.CR_SYS_START_DT_EST,
CR_SYSTEMIC.CR_SYS_END_DT,
CR_SYSTEMIC.CR_SYS_END_DT_EST,
CR_RADIATION.CR_RAD_START_DT,
CR_RADIATION.CR_RAD_START_DT_EST,
CR_RADIATION.CR_RAD_END_DT,
CR_RADIATION.CR_RAD_END_DT_EST,
CR_RADIATION.CR_RAD_PHYS,
CR_RADIATION.CR_RAD_DOSE,
CR_RADIATION.CR_RAD_NOTES,
CR_SURGERY.CR_SURGERY_DT,
CR_SURGERY.CR_SURGERY,
CR_SURGERY.CR_SURGEON,
CR_SURGERY.CR_SURGERY_DT_EST,
CR_SURGERY.CR_SURG_APPROACH,
CR_SURGERY.CR_SURGERY_SPEC,
CR_PATHOLOGY.CR_SURG_PT,
CR_PATHOLOGY.CR_SURG_PN,
CR_PATHOLOGY.CR_SURG_PM,
CR_PATHOLOGY.CR_SURG_HISTTYPE,
CR_PATHOLOGY.CR_SURG_TME,
CR_PATHOLOGY.CR_SURG_TME_REASON,
CR_PATHOLOGY.CR_SURG_TME_REASON_SPEC,
CR_PATHOLOGY.CR_SURG_DISTAL,
CR_PATHOLOGY.CR_SURG_MSI,
CR_PATHOLOGY.CR_SURG_CRM,
CR_PATHOLOGY.CR_SURG_PROX_DIST,
FU_STATUS.FU_DT,
FU_STATUS.FU_STATUS,
FU_STATUS.FU_CANCERSTATUS,
CR_LAB.CR_LAB_DT,
CR_LAB_TUMORMARKER.CR_LAB_TUMORMARKER,
CR_DISEASE_HISTORY.CR_FAM_HISTORY,
CR_GENTEST.CR_GENTEST,
CR_GENTEST.CR_GENTEST_SPEC,
CR_GENTEST.CR_GENTEST_DT,
CR_GENTEST.CR_GENTEST_RESULT
from
CR_IMAGING
left join patient
on CR_IMAGING.fk_SOCRD_ID=patient.SOCRD_ID
left join PT_IDENTIFIER
on patient.socrd_id=PT_IDENTIFIER.FK_SOCRD_ID
left join PT_STUDY
on patient.SOCRD_ID=PT_STUDY.FK_SOCRD_ID
left join CR_DISEASE_HISTORY
on CR_DISEASE_HISTORY.FK_SOCRD_ID=patient.SOCRD_ID
left join CR_MDT
on CR_MDT.FK_SOCRD_ID=PATIENT.SOCRD_ID
left join CR_MDT_RECOM
on CR_MDT.CR_MDT_ID=CR_MDT_RECOM.FK_CR_MDT_ID
left join tumorsite
on tumorsite.FK_SOCRD_ID=PATIENT.SOCRD_ID
left join CR_SYSTEMIC
on CR_SYSTEMIC.FK_SOCRD_ID=PATIENT.SOCRD_ID
left join CR_RADIATION
on CR_RADIATION.FK_SOCRD_ID=PATIENT.SOCRD_ID
left join CR_SURGERY
on CR_SURGERY.FK_SOCRD_ID=PATIENT.SOCRD_ID
LEFT JOIN FU_STATUS
ON FU_STATUS.FK_SOCRD_ID=PATIENT.SOCRD_ID
LEFT JOIN CR_LAB
ON CR_LAB.FK_SOCRD_ID=PATIENT.SOCRD_ID
LEFT JOIN CR_LAB_TUMORMARKER
ON CR_LAB_TUMORMARKER.FK_CR_LAB_ID=CR_LAB.CR_LAB_ID
left join CR_PATHOLOGY
on CR_PATHOLOGY.FK_CR_SURGERY_ID=CR_SURGERY.CR_SURGERY_ID,
cr_workupproc CR_WORKUPPROC
where cr_workupproc.FK_SOCRD_ID=patient.SOCRD_ID
and CR_DISEASE_HISTORY.FK_SOCRD_ID=patient.SOCRD_ID
and PT_STUDY=3
GROUP BY PT_STUDY.SUBJECT_NUMBER,
patient.PTLASTNAME, patient.PTFIRSTNAME,
CR_imaging.CR_IMAGING,
CR_IMAGING.CR_IMAGING_DT, patient.DOB,
CR_imaging.CR_IMG_SITE,
CR_IMAGING.CR_IMG_SITE_SPEC,
CR_imaging.CR_IMAGING_SPEC,
CR_IMAGING.CR_IMAGING_CT,
CR_IMAGING.CR_IMAGING_CN,
CR_IMAGING.CR_IMAGING_CM,
CR_WORKUPPROC.CR_WORKUPPROC,
CR_WORKUPPROC.CR_WORKUPPROC_DT,
CR_DISEASE_HISTORY.CR_DISEASE_HISTORY,
CR_DISEASE_HISTORY.CR_DISEASE_HISTORY_DT,
CR_MDT_RECOM.CR_MDT_RECOM,
CR_MDT.CR_MDT_DT,
CR_MDT.CR_MDT_PHYS,
CR_MDT.CR_MDT_PRESENTED,
CR_MDT.CR_MDT_HISTTYPE,
CR_MDT.CR_MDT_STAGE,
CR_MDT.CR_MDT_CT,
CR_MDT.CR_MDT_CN,
CR_MDT.CR_MDT_CM,
CR_MDT.CR_MDT_LOOKBACK,
CR_MDT.CR_MDT_PT,
CR_MDT.CR_MDT_PN,
CR_MDT.CR_MDT_PM,
CR_MDT_PATH_REVIEW_DT,
CR_MDT_PATH_REVIEW,
TUMORSITE.TUMORSITE,
TUMORSITE.TUMORSITE_SPEC,
TUMORSITE.RECURRENCE_DT,
TUMORSITE.RECURRENCE_DT_EST,
TUMORSITE.METASTASIS_DT,
TUMORSITE.METASTASIS_DT_EST,
CR_SYSTEMIC.CR_AGENT,
CR_SYSTEMIC.CR_AGENT_SPEC,
CR_SYSTEMIC.CR_SYS_CYCLE,
CR_SYSTEMIC.CR_SYS_DOSE_DAY,
CR_SYSTEMIC.CR_SYS_DOSE_TOTAL,
CR_SYSTEMIC.CR_SYS_START_DT,
CR_SYSTEMIC.CR_SYS_START_DT_EST,
CR_SYSTEMIC.CR_SYS_END_DT,
CR_SYSTEMIC.CR_SYS_END_DT_EST,
CR_RADIATION.CR_RAD_START_DT,
CR_RADIATION.CR_RAD_START_DT_EST,
CR_RADIATION.CR_RAD_END_DT,
CR_RADIATION.CR_RAD_END_DT_EST,
CR_RADIATION.CR_RAD_PHYS,
CR_RADIATION.CR_RAD_DOSE,
CR_RADIATION.CR_RAD_NOTES,
CR_SURGERY.CR_SURGERY_DT,
CR_SURGERY.CR_SURGERY,
CR_SURGERY.CR_SURGEON,
CR_SURGERY.CR_SURGERY_DT_EST,
CR_SURGERY.CR_SURG_APPROACH,
CR_PATHOLOGY.CR_SURG_PT,
CR_PATHOLOGY.CR_SURG_PN,
CR_PATHOLOGY.CR_SURG_PM,
CR_PATHOLOGY.CR_SURG_HISTTYPE,
CR_PATHOLOGY.CR_SURG_TME,
CR_PATHOLOGY.CR_SURG_TME_REASON,
CR_PATHOLOGY.CR_SURG_TME_REASON_SPEC,
CR_PATHOLOGY.CR_SURG_DISTAL,
CR_PATHOLOGY.CR_SURG_MSI,
CR_PATHOLOGY.CR_SURG_CRM,
CR_PATHOLOGY.CR_SURG_PROX_DIST,
PT_STUDY.FK_SOCRD_ID,
CR_MDT.CR_MDT_DIAG,
FU_STATUS.FU_DT,
FU_STATUS.FU_STATUS,
FU_STATUS.FU_CANCERSTATUS,
PT_IDENTIFIER_VALUE,
CR_MDT_RECOM.CR_MDT_RECOM_SPEC,
TUMORSITE.DIAGNOSIS_DT,
CR_LAB.CR_LAB_DT,
CR_LAB_TUMORMARKER.CR_LAB_TUMORMARKER,
CR_SURGERY.CR_SURGERY_SPEC
答案 0 :(得分:0)
它可能更好(如果仅为了可读性)不混合你的连接方法,所以我将内连接转换为
inner join cr_workupproc on cr_workupproc.FK_SOCRD_ID=patient.SOCRD_ID
和CR_DISEASE_HISTORY.FK_SOCRD_ID
查询中唯一的过滤器是
and PT_STUDY=3
但是pt_study似乎是一个表,或者这也是某个表上的一列?如果是这样的话,最好明确表明它与表限定符的位置。
如果这不是cr_imaging表上的列,那么您可能需要检查表顺序,因为您可能正在进行多次全表扫描。
此外,您应该获得查询的解释计划,以查看它正在做什么,这可以帮助您优化查询。