[답변]쿼리에 관련해서 질문을 드립니다... 0 0 1,445

by 이주호 [2007.02.14 11:19:10]


양식이 고정되었을 경우에만 아래 query 사용 가능할듯 합니다.

허접하지만 참고하세요.

 

select a.이름
       ,a.포인트
from (
        select case when b.rn=1 and a.이름='경실' then 0
                     when b.rn=1 and a.이름='김민' then 9.5
                     when b.rn=3 and a.이름='경실' then 9.4
                     when b.rn=3 and a.이름='김민' then 13
                     else rownum
                end num
               ,case when b.rn=1 then '이름'
                     when b.rn=3 then '소계'
                     else a.이름
                 end 이름
               ,case when b.rn=1 then '포인트' else to_char(sum(a.포인트) over (partition by case when b.rn=1 and a.이름='경실' then 0
                                                                                                        when b.rn=1 and a.이름='김민' then 9.4
                                                                                                        when b.rn=3 and a.이름='경실' then 9.5
                                                                                                        when b.rn=3 and a.이름='김민' then 13
                                                                                                   else rownum
                                                                                                   end
                                                                                                  ,case when b.rn=1 then '이름'
                                                                                                        when b.rn=3 then '소계'
                                                                                                        else a.이름
                                                                                                   end))
                end 포인트
        from (
                select '경실' 이름, 400 포인트 from dual union all
                select '경실', 2200 from dual union all
                select '경실', 400 from dual union all
                select '김민', 1200 from dual union all
                select '김민', 1000 from dual union all
                select '김민', 1200 from dual
              ) a,
              (
                select rownum rn from dual connect by level < 4
              ) b,
              (
                select '이름' 이름, '포인트' 포인트 from dual
              ) c
      ) a
group by a.num
         ,a.이름
         ,a.포인트
order by a.num

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