-3
請看以下示例數據和情景顯示一定值
with data_1 as (
select 'Book' as object,'Long-Ruled' as Type,20 as Amount from dual
union
select 'Book' as object,'Short-Ruled' as Type,30 as Amount from dual
union
select 'Book' as object,'All Type' as Type,5 as Amount from dual
union
select 'Pen' as object,'Fountain' as Type,55 as Amount from dual
union
select 'Pen' as object,'All Type' as Type,100 as Amount from dual
)
我希望我的輸出是作爲附加的圖像
Object Type Amount Certain_Amount
Book Long-Ruled 20 5
Book Short-Ruled 30 5
Book All Type 5 5
Pen Fountain 55 100
Pen All Type 100 100
我想要添加顯示「所有類型」金額的新列「確定金額」。
我試過了下面的查詢。
select object,type,amount,sum(sub) over (partition by object) as certain_amount from
(
select object,type,amount,case when type not like 'All Type' then 0 else amount end as sub from data_1
)
我能達到所需的輸出從上面query.is他們一個簡單的方法來做到這一點單查詢發佈我得到的答案
選擇對象,鍵入問題後.thanks