SUMSEN

Oracle&Sql爱好者,用友NC管理员

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

如下图

with a as (select t.outflag,t.pk_corp, t.subjcode from bd_accsubj t where t.pk_accsubj in ('0001E11000000000050W','0001N510000000000OZW') )
 

SELECT distinct *
      FROM (SELECT you.subjcode,nvl(you.outflag, me.outflag) outflag, nvl(you.pk_corp, me.pk_corp )pk_corp
              FROM  a you
              left join a me
              on you.subjcode = me.subjcode)
    WHERE outflag is not null
     and pk_corp is not null

 ps:这里红色的subjcode需要指定表you,me都可以

下面的max用法也可以,原理是null字段是无限大,max的时候就忽略了

SELECT  subjcode, max(outflag),max(pk_corp )  FROM  a  group by subjcode

 

 

或者

posted on 2012-09-27 15:58  sumsen  阅读(2174)  评论(0编辑  收藏  举报