现在有一张表 字段 id value 需要统计出这样一个数据表:
------------------
id value
100 2000
101 200
102 400
103 600
104 800
-------------------
实际在表中的数据是这样
-------------------
id value
100 800
101 200
102 400
103 600
104 0
-------------------
就是把id为100的值转换为id为104的值,同时id为100的value为其他四个的总和
------解决方案--------------------
with t as ( select 100 id ,800 value from dual
union ALL select 101 id ,200 value from dual
union ALL select 102 id ,400 value from dual
union ALL select 103 id ,600 value from dual
union ALL select 104 id ,0 value from dual )
SELECT T.ID,
DECODE(T.ID,
104,
(SELECT VALUE FROM T WHERE ID = 100),
100,
(SELECT SUM(VALUE) FROM T WHERE ID <> 104),
T.VALUE)
FROM T T