ROW의 SUMMARY 하는 쿼리 문의 0 2 1,533

by 김성수 [SQL Query] [2014.12.19 09:06:32]


with base as
(
    select 'ITEM1' as ITEM, 1 as A, 4 as B, 2 as C, 3 as D from dual
    union all
    select 'ITEM2' as ITEM, 1 as A, 4 as B, 2 as C, 3 as D from dual
    union all
    select 'TOTAL' as ITEM, 2 as A, 8 as B, 4 as C, 6 as D from dual
)
select * from base;

BASE 테이블 값 추가하고싶은값
ITEM A B C D SUMMARY
ITEM1 1 4 2 3 10
ITEM2 1 4 2 3 10
TOTAL 2 8 4 6 20

 

위와같이 SUMMARY에 ROW의 값을 SUM 하고싶어서 문의 드립니다.

 

 

by 아발란체 [2014.12.19 09:11:47]
WITH BASE AS (
  select 'ITEM1' as ITEM, 1 as A, 4 as B, 2 as C, 3 as D from dual
  union all
  select 'ITEM2' as ITEM, 1 as A, 4 as B, 2 as C, 3 as D from dual
  union all
  select 'TOTAL' as ITEM, 2 as A, 8 as B, 4 as C, 6 as D from dual
 )
 SELECT BASE.*, a + b + c + d AS summary FROM BASE 
 ;

 


by 우리집아찌 [2014.12.19 09:19:51]
SELECT A , B, C, D , NVL(A,0) + NVL(B,0) + NVL(C,0) + NVL(D,0) AS SUMMARY FROM BASE

 

댓글등록
SQL문을 포맷에 맞게(깔끔하게) 등록하려면 code() 버튼을 클릭하여 작성 하시면 됩니다.
로그인 사용자만 댓글을 작성 할 수 있습니다. 로그인, 회원가입