楼主的方法不对:
试以下我的。
select type,
max(case when STATUE1=01 AND STATUE2=01 then fee end) total1,
max(case when STATUE1=01 AND STATUE2=02 then fee end) total2,
max(case when STATUE1=02 AND STATUE2=01 then fee end) total3,
max(case when STATUE1=02 AND STATUE2=02 then fee end) total4
from
(select type,sum(fee1)+sum(fee2) fee,status1,status2
from  TABLE_USER,TABLE_FEE 
WHERE TABLE_USER.ID=TABLE_FEE.ID 
GROUP BY type,status1,status2) t
group by type

解决方案 »

  1.   

    平平淡淡大哥,你这个“then fee ”是什么意思啊?
      

  2.   

    在FROM这句有错
    missing expression!
      

  3.   

    In a simple CASE expression, Oracle searches for the first WHEN ... THEN pair for which expr is equal to comparison_expr and returns return_expr. If none of the WHEN ... THEN pairs meet this condition, and an ELSE clause exists, then Oracle returns else_expr. Otherwise, Oracle returns null. You cannot specify the literal NULL for all the return_exprs and the else_expr.
      

  4.   

    case when STATUE1=02 AND STATUE2=02 then fee
    如果满足STATUE1=02 AND STATUE2=02结果就显示 fee.
      

  5.   

    我看不出错误。可能是字符错误。
    select type,
    max(case when STATUE1='01' AND STATUE2='01' then fee end) total1,
    max(case when STATUE1='01' AND STATUE2='02' then fee end) total2,
    max(case when STATUE1='02' AND STATUE2='01' then fee end) total3,
    max(case when STATUE1='02' AND STATUE2='02' then fee end) total4
    from
    (select type,sum(fee1)+sum(fee2) fee,status1,status2
    from  TABLE_USER,TABLE_FEE 
    WHERE TABLE_USER.ID=TABLE_FEE.ID 
    GROUP BY type,status1,status2) t
    group by type
      

  6.   

    create table test as
    select type,status1,status2,sum(f) total_fee
    from table_user a,
    (select id,status1,status2,sum(fee1)+sum(fee2) f from table_fee 
           group by id,status1,status2) b
    where a.id=b.id 
    group by type,status1,status2;
      

  7.   

    SELECT TYPE ,SUM(decode(statue1,'01',decode(statue2,'01',FEE1+FEE2))) TOTAL1,
                 SUM(decode(statue1,'01',decode(statue2,'02',FEE1+FEE2))) TOTAL2,
                 SUM(decode(statue1,'02',decode(statue2,'01',FEE1+FEE2))) TOTAL3,
                 SUM(decode(statue1,'02',decode(statue2,'02',FEE1+FEE2))) TOTAL4
    FROM TABLE_USER,TABLE_FEE
    WHERE TABLE_USER.ID=TABLE_FEE.ID
    GROUP BY TYPE