1)想要与主键OR_LOG.LOG_ID相关联的所有记录,其中OR_LOG.LOC_ID = 4060020
2)如果在脚本中列出的时间之间列出了列出的Medication_ID,则希望列输出“是”或“否”。我真的想要包括4种药物,并且如果有任何一种药物,则会有“是”或“否”。
3)在添加两个时间限制之前,我能够做到这一点,除了它似乎只显示包含药物的行。我认为左联盟将会照顾到这一点。当我添加两个“和”时间语句时,我收到了“无效字符”错误。
4)我将使用不同的时间帧和不同的drug_ID运行更多相同类型的子查询。
5)数据库非常庞大,我尽力提高效率。
SELECT
CLARITY.OR_LOG.LOC_ID,
CLARITY.V_LOG_BASED.PRIMARY_PREOP_NURSE_NM,
CLARITY.V_LOG_BASED.PRIMARY_PROCEDURE_NM,
CLARITY.V_LOG_BASED.PRIMARY_PHYSICIAN_NM,
CLARITY.F_AN_RECORD_SUMMARY.AN_52_ENC_CSN_ID,
CLARITY.V_LOG_BASED.PRIMARY_RECOVERY_NURSE_NM,
CLARITY.V_LOG_BASED.IN_OR_DTTM,
CLARITY.V_LOG_BASED.OUT_OR_DTTM,
Case
When CLARITY.ORDER_MED.MEDICATION_ID = 104661
and CLARITY.MAR_ADMIN_INFO.TAKEN_TIME > CLARITY.V_LOG_TIMING_EVENTS.PATIENT_IN_PREPROCEDURE_DTTM
and CLARITY.MAR_ADMIN_INFO.TAKEN_TIME < CLARITY.V_LOG_TIMING_EVENTS.PATIENT_OUT_ROOM_DTTM
then 'YES'
else 'NO' END AS PONV
FROM CLARITY.OR_LOG
INNER JOIN CLARITY.F_AN_RECORD_SUMMARY
ON CLARITY.OR_LOG.LOG_ID = CLARITY.F_AN_RECORD_SUMMARY.LOG_ID
INNER JOIN CLARITY.V_LOG_BASED
ON CLARITY.OR_LOG.LOG_ID = CLARITY.V_LOG_BASED.LOG_ID
left JOIN CLARITY.MAR_ADMIN_INFO
ON CLARITY.F_AN_RECORD_SUMMARY.AN_52_ENC_CSN_ID = CLARITY.MAR_ADMIN_INFO.MAR_ENC_CSN
inner JOIN CLARITY.ORDER_MED
ON CLARITY.MAR_ADMIN_INFO.ORDER_MED_ID = CLARITY.ORDER_MED.ORDER_MED_ID
INNER JOIN CLARITY.V_LOG_TIMING_EVENTS
ON CLARITY.F_AN_RECORD_SUMMARY.LOG_ID = CLARITY.V_LOG_TIMING_EVENTS.LOG_ID
WHERE CLARITY.OR_LOG.LOC_ID = 4060020