不再有假脱机空间错误-select语句

时间:2019-01-16 19:43:17

标签: sql teradata

假脱机空间错误

我运行了查询,但收到了no more spool space in ID错误。当我删除2个select语句(在from语句之上)时,它运行良好。请帮助优化查询。

select NOT_FILETM_LOC_DTTM as documented_date, HNO_INFO.pat_enc_csn_id, AUTHOR_USER_ID, clarity_emp.name as md,patient.pat_id,hno_note_text.note_text, pat_mrn_id, cast(NOT_FILETM_LOC_DTTM as date) - cast( patient.birth_date as date) year (4) as age,
(select department_name from clarity_dep, clarity_adt where clarity_adt.department_id = dep.department_id and event_id  = 
(select max(event_id)  from clarity_adt adt where pat_enc_hsp.pat_enc_csn_id = adt.pat_enc_csn_id and adt.EVENT_SUBTYPE_C <> 2 and adt.event_type_c<>6  and adt.effective_time <= NOT_FILETM_LOC_DTTM) ) as  unit
from HNO_INFO,  hno_note_text, NOTE_ENC_INFO, clarity_emp, patient, pat_enc_hsp
 where OTE_ENC_INFO.note_id = HNO_INFO.note_id
   and hno_note_text.note_id = HNO_INFO.note_id
   and hno_note_text.note_text like  ('%Procedural Sedation Stop Time:%')
   and (hno_note_text.note_text like  ('%PICC%') or hno_note_text.note_text like  ('%Lumbar Puncture%'))
   and emp.user_id = AUTHOR_USER_ID
   and patient.pat_id = HNO_INFO.pat_id
   and pat_enc_hsp.pat_enc_csn_id = HNO_INFO.pat_enc_csn_id
   and cast(documented_date  as date) >= '2018-01-01'
   qualify row_number() over (partition by HNO_INFO.pat_enc_csn_id order by documented_date  )=1

1 个答案:

答案 0 :(得分:1)

好的,让我们尝试一下:

select
  NOT_FILETM_LOC_DTTM as documented_date
  , HNO_INFO.pat_enc_csn_id, 
  AUTHOR_USER_ID, emp."NAME" as md,patient.pat_id,hno_note_text.note_text, pat_mrn_id
  , cast(NOT_FILETM_LOC_DTTM as date) - cast( patient.birth_date as date) year (4) as age
  , department_name  unit
  , adt.event_id    
from HNO_INFO
  ,  hno_note_text
  , NOTE_ENC_INFO
  , clarity_emp emp
  , patient
  , pat_enc_hsp
  ,clarity_dep
  --, clarity_adt 
   ,(select max(event_id) event_id, adt.pat_enc_csn_id, department_id, effective_time   from clarity_adt adt
     where  adt.EVENT_SUBTYPE_C <> 2 and adt.event_type_c<>6  
      group by adt.pat_enc_csn_id, department_id, effective_time
    ) adt    
 where 
   NOTE_ENC_INFO.note_id = HNO_INFO.note_id
   and adt.department_id = clarity_dep.department_id 
   and pat_enc_hsp.pat_enc_csn_id = adt.pat_enc_csn_id 
   and adt.effective_time <= NOT_FILETM_LOC_DTTM

   and hno_note_text.note_id = HNO_INFO.note_id

   and hno_note_text.note_text like  ('%Procedural Sedation Stop Time:%')
   and (hno_note_text.note_text like  ('%PICC%') or hno_note_text.note_text like  ('%Lumbar Puncture%'))

   and emp.user_id = AUTHOR_USER_ID
   and patient.pat_id = HNO_INFO.pat_id
   and pat_enc_hsp.pat_enc_csn_id = HNO_INFO.pat_enc_csn_id
   and cast(documented_date  as date) >= '2018-01-01'
   qualify row_number() over (partition by HNO_INFO.pat_enc_csn_id order by documented_date  )=1
;