楼主的方法不对:
试以下我的。
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
解决方案 »
- 安装的日志文件路径
- 这句SQL跑了5个小时才出结果。请教大侠:如何提高配置参数和优化SQL?
- timestamp类型,如何加1秒?
- declare,if简单常识求教
- 请问,pl/sql中的tool => session 能保持多长时间?
- 高分求救ORACLE故障
- 紧急求助:ora-27100 shared memory realm already exists
- 为什么我的电脑装不了oracle8.16??
- 有谁知道report中的矩阵查询是怎么一回事吗?
- oracle update 多个字段,能不能 只要其中一个字段有值 这条记录就不更新
- 请问用9i的客户端中的EXP 去倒8.0.4.0.0服务器的数据,会不会有问题???请帮忙
- 请教一个安装Oracle的问题
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