当前位置: 代码迷 >> PB >> 检索条件!解决方案
  详细解决方案

检索条件!解决方案

热度:45   发布时间:2016-04-29 08:46:54.0
检索条件!
检索病历操作,首先每个病历都有一个叫ICD10_CODE的编码 ICD10_CODE在表1中 随访日期在表2中 出院时间在表3中
条件一:ICD10_CODE在C00.0--C97.0 与 D32.0--D33.9之间的病历 且出院时间(out_time)大于6个月
条件二:距离上次随访日期(visit_date)的时间大于6个月 
这样的检索条件在PB中咋写

------解决方案--------------------
SQL code
select a.* from 表1 awhere ((a.ICD10_CODE between 'C00.0' and 'C97.0') or (a.ICD10_CODE between 'D32.0' and 'D33.9')) and not exists(select 1 from 表2 b where b.ICD10_CODE = a.ICD10_CODE and datediff(mm, b.visit_date, getdate()) < 6 )and exists(select 1 from 表3 c where c.ICD10_CODE = a.ICD10_CODE and datediff(mm, c.out_time, getdate()) >= 6 )
------解决方案--------------------
帮你搜了一下,这是别人写的,oracle的自定义函数datediff

C/C++ code
create   or   replace   function   --   --   works   in   roughly   the   same   way   as   sybase   datsdiff --   call   would   be   eg.   datediff( 'month ',date1,date2) --   p_what   would   be   'HOUR ',   'DAY ', 'MONTH '   OR   'QUARTER ' datediff(   p_what   in   varchar2,                     p_d1       in   date,                   p_d2       in   date   )   return   number as l_result         number; begin         l_result:=null;         if   (upper(p_what)   =   'HOUR ')   then             l_result:=((p_d2-p_d1)*24);         end   if;         if   (upper(p_what)   =   'DAY ')   then             l_result:=(p_d2-p_d1);         end   if;         if   (upper(p_what)   =   'MONTH ')   then             l_result:=round(MONTHS_BETWEEN(p_d2,p_d1),0);         end   if;         if   (upper(p_what)   =   'QUARTER ')   then             l_result:=((floor(MONTHS_BETWEEN(p_d2,TRUNC(p_d2, 'YEAR '))/3)+1)   -   (floor(MONTHS_BETWEEN(p_d1,TRUNC(p_d1, 'YEAR '))/3)+1)   +   (((to_char(p_d2,   'yyyy '))   -   (to_char(p_d1,   'yyyy ')))*4));         end   if;     l_result:=floor(l_result);     return   l_result; end; ---------------------------------------------
  相关解决方案