select staffid 员工号  , sum(case  when type = 0  money else  0  end ) 正常金额, 
      sum(case  when type = 1 money else  0  end ) 异常金额 ,sum(money ) 所有金额
group staffid.
具体case语法查询一下帮助,可能有问题。

解决方案 »

  1.   

    SELECT A.staffid,SUM(A.money) 
    FROM A
    WHERE A.type = '0'
    GROUP BY A.staffid
    union
    SELECT SUM(A.money) 
    FROM A
    WHERE A.type = '1'
    GROUP BY A.staffid
    union
    SELECT SUM(A.money) 
    FROM A
    GROUP BY A.staffid
      

  2.   

    select 
        a.staffid 员工号,
        sum(decode(a.type,0,a,money,0)) 正常金额总和,
        sum(decode(a.type,1,a.money,0)) 异常金额总和,
        sum(a.money) 所有金额
    from 
        tablea a 
    group by 
        a.staffid
      

  3.   

    --输错一个逗号
    select 
        a.staffid 员工号,
        sum(decode(a.type,0,a.money,0)) 正常金额总和,
        sum(decode(a.type,1,a.money,0)) 异常金额总和,
        sum(a.money) 所有金额
    from 
        tablea a 
    group by 
        a.staffid
      

  4.   

    select staffid 员工号,
           sum(decode(type,0,money,0)) 正常金额,
           sum(decode(type,1,money,0)) 异常金额,
           sum(money) 所有金额
    from   table_name
    group by staffid
      

  5.   

    SQL>select
      2      staffid 员工号,
      3      sum(decode(type,0,money,0)) 正常金额总和,
      4      sum(decode(type,1,money,0)) 异常金额总和,
      5      sum(a.money) 所有金额
      6  from
      7      a
      8  group by
      9*     staffid
    SQL> /员工号               正常金额总和 异常金额总和 所有金额
    -------------------- ------------ ------------ ----------
    001                           100          200        300
    002                           500          700       1200
    003                          1500         1200       2700
    004                          2000            0       2000SQL>
      

  6.   

    select staffid,sum(decode(type,0,money,0)),sum(decode(type,1,money,0)),sum(money) from tablename group by staffid