简体   繁体   English

使用 AWS athena 的时间戳差异

[英]Timestamps differences using AWS athena

I am running an SQL query using AWS Athena in my jupyter notebook as follows.我在我的 jupyter 笔记本中使用 AWS Athena 运行 SQL 查询,如下所示。 It involves computing differences between timestamps as follows.它涉及计算时间戳之间的差异,如下所示。

query_demog = """


select ad.subject_id, ad.hadm_id, i.icustay_id ,
       date_diff('second', timestamp '1970-01-01 00:00:00', ad.admittime) as admittime,
       date_diff('second', timestamp '1970-01-01 00:00:00', ad.dischtime) as dischtime,
       ROW_NUMBER() over (partition by ad.subject_id order by i.intime asc) as adm_order,
       case when i.first_careunit='NICU' then 5
            when i.first_careunit='SICU' then 2
            when i.first_careunit='CSRU' then 4
            when i.first_careunit='CCU' then 6
            when i.first_careunit='MICU' then 1
            when i.first_careunit='TSICU' then 3
       end as unit,
       date_diff('second', timestamp '1970-01-01 00:00:00', i.intime) as intime,
       date_diff('second', timestamp '1970-01-01 00:00:00', i.outtime) as outtime,
       i.los,
from mimiciii.admissions ad,
     mimiciii.icustays i,
     mimiciii.patients p
where ad.hadm_id=i.hadm_id and p.subject_id=i.subject_id 
order by subject_id asc, intime asc

"""

It works fine.它工作正常。 Now when I include another line having similar timestamps differences, I get an error.现在,当我包含另一行具有类似时间戳差异的行时,出现错误。

query_demog = """


select ad.subject_id, ad.hadm_id, i.icustay_id ,date_diff('second', timestamp '1970-01-01 00:00:00', ad.admittime) as admittime, date_diff('second', timestamp '1970-01-01 00:00:00', ad.dischtime) as dischtime, ROW_NUMBER() over (partition by ad.subject_id order by i.intime asc) as adm_order, case when i.first_careunit='NICU' then 5 when i.first_careunit='SICU' then 2 when i.first_careunit='CSRU' then 4 when i.first_careunit='CCU' then 6 when i.first_careunit='MICU' then 1 when i.first_careunit='TSICU' then 3 end as unit,  date_diff('second', timestamp '1970-01-01 00:00:00', i.intime) as intime, date_diff('second', timestamp '1970-01-01 00:00:00', i.outtime) as outtime, i.los,

 EXTRACT(EPOCH FROM (i.intime-p.dob)::INTERVAL)/86400 as age





from mimiciii.admissions ad, mimiciii.icustays i, mimiciii.patients p

where ad.hadm_id=i.hadm_id and p.subject_id=i.subject_id 

order by subject_id asc, intime asc

"""

The inclusion of the line EXTRACT(EPOCH FROM (i.intime-p.dob)::INTERVAL)/86400 as age creates an error as follows.EXTRACT(EPOCH FROM (i.intime-p.dob)::INTERVAL)/86400 as age会产生如下错误。

An error occurred (InvalidRequestException) when calling the StartQueryExecution operation: line 3:37: mismatched input ':' expecting {'.', ')', '[', 'AT', '+', '-', '*', '/', '%', '||'} unable to rollback调用 StartQueryExecution 操作时发生错误 (InvalidRequestException):第 3:37 行:不匹配的输入 ':' 期望 {'.', ')', '[', 'AT', '+', '-', '* ', '/', '%', '||'} 无法回滚

I don't know why the inclusion of EXTRACT(EPOCH FROM (i.intime-p.dob)::INTERVAL)/86400 as age creates an error我不知道为什么包含EXTRACT(EPOCH FROM (i.intime-p.dob)::INTERVAL)/86400 as age会产生错误

to_unixtime()内置应该工作:

to_unixtime(i.intime-p.dob)/86400 as age

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM