-- TABLE A에 ITEM이 유일하다고 가정
select b.item
, DECODE(REPLACE(A.ITEM,'F'),A.ITEM, (a.qty+a.price)
,(SELECT (qty+price) FROM tableA WHERE ITEM = REPLACE(A.ITEM,'F') )
) QP_SUM
from table a, table b
where a.item = b.item
;
select b.item
, DECODE((a.qty+a.price), NULL
, (SELECT (qty+price) FROM tableA WHERE ITEM = REPLACE(A.ITEM,'F') )
, (a.qty+a.price)
) QP_SUM
from table a, table b
where a.item = b.item
;
또 여쭤봐서 죄송합니다ㅜㅜ
item뿐만아니라 여러가지가 들어있는데 마지막 F를 체크할수있는 방법이 있을까요..?
SELECT SUBSTR('ABDHF',-1,1) FROM DUAL
이렇게 하시면 마지막 글자를 추출 할 수 있습니다.
select b.item, sum(a.qty+a.price) from table a, table b where a.item = decode(substr(b.item,-1),'F',substr(b.item,1,length(b.item)-1),b.item) group by b.item
답변주신분들 정말 감사합니다..ㅜㅜ
공교롭게도 MSSQL이라 SUBSTR도 안먹히고 REPLACE도 마지막문자열을 어떻게 가져오는지 모르겠네요...CASE로 바꾸고있는데 제가잘못하고있는건지 확인을좀 해봐야겠네요ㅜㅠ