楼主的方法不对:
试以下我的。
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
试以下我的。
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
missing expression!
如果满足STATUE1=02 AND STATUE2=02结果就显示 fee.
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
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;
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