select distinct a.indi_id,a.name,decode(a.sex,1,'男','女') as sex,trunc(months_between(sysdate,a.birthday)/12) as birthday,a.idcard, c.insur_org_no,c.insur_org_name, b.corp_id,b.corp_code,b.corp_name,b.linkman,b.linkman_phone, a.address,a.post_code,a.telephone 
from bs_insured a, bs_corp b, bs_insur_org c ,bs_out_change d,bs_out e
where a.corp_id = b.corp_id and a.insur_org_no = c.insur_org_no and a.indi_id = e.indi_id and d.leave_no=e.leave_no 
and d.leave_no=(case  
when  (select max(leave_no) from bs_out where  indi_id=210384  and audit_flag <>2 and d.change_content<>'insur_org_no' and d.change_content<>'hospital_id')is not null
 then (select max(leave_no) from bs_out where  indi_id=210384  and audit_flag <>2 and d.change_content<>'insur_org_no' and d.change_content<>'hospital_id')
else null
end)
AND a.indi_sta = 1 
AND a.indi_id = 210384
and b.corp_type_code <> 80 重点在红色那两句,我想请问一下,如何使的,当else的时候and d.leave_no=不执行

解决方案 »

  1.   

    补充一下当else的时候and   d.leave_no=        不执行(意思就是没有and d.leave_no= 这个条件了)
      

  2.   

    我觉得LZ的意思是当else时不会筛选结果集中的记录吧?我的想法是当else的时候 'and d.leave_no=d.leave_no' 这样就好了吧?
      

  3.   

    就是 else的时候and  d.leave_no =的这个条件都相当不存在,变成
    select distinct a.indi_id,a.name,decode(a.sex,1,'男','女') as sex,trunc(months_between(sysdate,a.birthday)/12) as birthday,a.idcard, c.insur_org_no,c.insur_org_name, b.corp_id,b.corp_code,b.corp_name,b.linkman,b.linkman_phone, a.address,a.post_code,a.telephone 
    from bs_insured a, bs_corp b, bs_insur_org c ,bs_out_change d,bs_out e
    where a.corp_id = b.corp_id and a.insur_org_no = c.insur_org_no and a.indi_id = e.indi_id and d.leave_no=e.leave_no 
    AND a.indi_sta = 1 
    AND a.indi_id = 210384
    and b.corp_type_code <> 80  相当去掉了那and后面的东西.这样怎么实现?
      

  4.   

    那就把else null 改成 else e.leave_no 就好了 ...