檢查:
with t as (
select 1 as ready_1,
2 as ready_2,
3 as ready_3,
1 as in_process,
4 as fail,
5 as crash,
'5/4/2017' as dat
from dual
union all
select 2 as ready_1,
2 as ready_2,
3 as ready_3,
1 as in_process,
4 as fail,
0 as crash,
'5/5/2017' as dat
from dual
)
select dat, prod_stat, max(suc) over(partition by dat) as success, sum(value) over(partition by dat) as total
from (
select dat, prod_stat, value, sum(value) over (partition by dat) as suc
from t
unpivot(
value for prod_stat in (ready_1, ready_2, ready_3)
)
union all
select dat, prod_stat, value, null as suc
from t
unpivot(
value for prod_stat in (in_process, fail, crash)
)
)
結果:
DAT PROD_STAT SUCCESS TOTAL
5/4/2017 READY_2 6 16
5/4/2017 READY_1 6 16
5/4/2017 CRASH 6 16
5/4/2017 FAIL 6 16
5/4/2017 IN_PROCESS 6 16
5/4/2017 READY_3 6 16
5/5/2017 FAIL 7 12
5/5/2017 IN_PROCESS 7 12
5/5/2017 CRASH 7 12
5/5/2017 READY_2 7 12
5/5/2017 READY_1 7 12
5/5/2017 READY_3 7 12
我認爲你可以使用'pivot'在甲骨文完成這件事。 – Alam