2016-12-23 1 views
-3

아래의 샘플 데이터를 찾아주세요 및 시나리오 내 출력이 첨부 된 이미지표시 특정 값

enter image description here

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 

I처럼되고 싶어

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 
) 

"모든 유형"금액을 나타내는 새로운 컬럼 "특정 금액"을 추가하려고합니다.

나는 아래 쿼리를 시도했다. 위는 단일 쿼리 내가 대답

선택 객체 유형을 가지고 질문을 게시 한 후

답변

0

을 .thanks 할 자신의 간단한 방법을 query.is에서

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 
) 

은 내가 필요한 출력을 얻을 수 있습니다 금액, 합계 (유형이 '모든 유형'과 같지 않은 경우 0 이외의 금액 끝) over (파티션 별 개체) over sub (데이터 _1)