select source , sum(decode(kind,8,1,0) ) as kind1 , sum(decode(kind,9,1,0) ) as kind2 from tab1 group by source 

解决方案 »

  1.   

    假设你的表名为redcom,下面语句中的src就是你的表中的source
    SQL> create table me as select
      2  src,nvl(sum(decode(kind,8,k)),0) k8,nvl(sum(decode(kind,9,k)),0) k9
      3  from (select src,kind,count(*) k from redcom group by src,kind)
      4  group by src;Table createdSQL> select * from me;SRC          K8         K9
    ---- ---------- ----------
    cs            0          1
    df            2          1
    js            2          2SQL>
      

  2.   

    一样的
    select id     ,source  ,  kind   ,  note  , decode(kind,8,kind,null) as kind1 , decode(kind,9,kind,null)  as kind2 from tab1
      

  3.   

    oracle中的tb1与tb2全联结语法是怎样的?
    请各位兄台赐教!谢谢
      

  4.   

    select source , sum(decode(kind,8,1,0) ) as kind1 , sum(decode(kind,9,1,0) ) as kind2 from tab1 group by source