oracle 逻辑写,千万不要把很复杂的逻辑写到一个sql语句中,求助~~~ 已解决 ->10#...

select record_time,ward_code,ward_name,bed_no,patient_id,pat_name,fall,fall_damage,drop_bed,lost,suicide,pipeline_slippage,other,result

from(

select case when cnt > 1 and rn = 1 then null else id end id,record_time,ward_code,ward_name,bed_no,patient_id,pat_name,

fall,fall_damage,drop_bed,lost,suicide,pipeline_slippage,other,result

from(

select row_number() over(partition by id,patient_id order by record_time) rn,

count(*) over(partition by id,patient_id) cnt,

id,record_time,ward_code,max(ward_name) ward_name,max(bed_no) bed_no,patient_id,max(pat_name) pat_name,

max(decode(section_name,'事件',decode(record,'跌倒','1',null),null)) as fall,

max(decode(section_name,'事件',decode(record,'摔伤','1',null),null)) as fall_damage,

max(decode(section_name,'事件',decode(record,'坠床','1',null),null)) as drop_bed,

max(decode(section_name,'事件',decode(record,'走失','1',null),null)) as lost,

max(decode(section_name,'事件',decode(record,'自杀','1',null),null)) as suicide,

max(decode(section_name,'管道名称',decode(record,null,null,1),null)) as pipeline_slippage,

max(case when section_name = '事件' and record not in('跌倒','摔伤','坠床','走失','自杀','管道滑脱') then record end) as other,

max(decode(section_name,'转归',record,null)) as result

from(

select nrft.id,nrf.ward_code,nrf.ward_name,nrf.bed_no,nrf.patient_id,nrf.pat_name,nrf.record_time,nr.item_id,nr.record,nrfs.section_name

from nursing_record_forms nrf,

nursing_record_form_templates nrft,

nursing_record_form_sections nrfs,

nursing_record_form_items nrfi,

nursing_records nr

where nrf.template_id = nrft.id

and nrfs.template_id = nrf.template_id

and nrfs.sequence in(1,6,4)

and nrfs.id = nrfi.section_id

and nr.form_id = nrf.id

and nr.section_id = nrfs.id

and nr.item_id = nrfi.item_id

and nrft.name in('走失危险因素评估报告表','跌倒/摔伤/坠床危险因素评估报告表','自杀危险因素评估报告表','病人管道滑脱评估报告表')

and nrf.record_time >= trunc(to_date(?,'yyyy-mm-dd hh24:mi:ss'),'year')

and nrf.record_time <= trunc(to_date(?,'yyyy-mm-dd hh24:mi:ss'),'year') - interval '1' second

) group by id,patient_id,record_time,ward_code)) where id is not null

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值