반응형
with base_data as (
  select '삼성제약' stock_name, '001360' stock_code, '의약품' sector_name from dual union all 
  select '삼성제약' stock_name, '001360' stock_code, '제조업' sector_name from dual union all 
  select '삼성제약' stock_name, '001360' stock_code, '소형(시가총액)' sector_name from dual union all 
  select '한국주철관공업' stock_name, '000970' stock_code, '철강,금속' sector_name from dual union all 
  select '한국주철관공업' stock_name, '000970' stock_code, '제조업' sector_name from dual union all 
  select '한국주철관공업' stock_name, '000970' stock_code, '소형(시가총액)' sector_name from dual union all 
  select '덕성' stock_name, '004830' stock_code, '제조업' sector_name from dual union all 
  select '덕성' stock_name, '004830' stock_code, '화학' sector_name from dual union all 
  select '덕성' stock_name, '004830' stock_code, '소형(시가총액)' sector_name from dual union all 
  select '케이티' stock_name, '030200' stock_code, '통신업' sector_name from dual union all 
  select '케이티' stock_name, '030200' stock_code, '코스피 200 저변동성지수' sector_name from dual union all 
  select '케이티' stock_name, '030200' stock_code, '코스피 200 고배당지수' sector_name from dual union all 
  select '케이티' stock_name, '030200' stock_code, 'KOSPI50지수' sector_name from dual union all 
  select '케이티' stock_name, '030200' stock_code, 'KOSPI100지수' sector_name from dual union all 
  select '케이티' stock_name, '030200' stock_code, 'KOSPI200지수' sector_name from dual union all 
  select '케이티' stock_name, '030200' stock_code, '대형(시가총액)' sector_name from dual union all 
  select '쎌마테라퓨틱스' stock_name, '015540' stock_code, '서비스업' sector_name from dual union all 
  select '쎌마테라퓨틱스' stock_name, '015540' stock_code, '소형(시가총액)' sector_name from dual union all 
  select '현대엘리베이터' stock_name, '017800' stock_code, '기계' sector_name from dual union all 
  select '현대엘리베이터' stock_name, '017800' stock_code, 'KOSPI200지수' sector_name from dual union all 
  select '현대엘리베이터' stock_name, '017800' stock_code, 'KOSPI200 중공업' sector_name from dual union all 
  select '현대엘리베이터' stock_name, '017800' stock_code, '제조업' sector_name from dual union all 
  select '현대엘리베이터' stock_name, '017800' stock_code, '중형(시가총액)' sector_name from dual union all 
  select '케이씨씨' stock_name, '002380' stock_code, '제조업' sector_name from dual union all 
  select '케이씨씨' stock_name, '002380' stock_code, 'KOSPI200지수' sector_name from dual union all 
  select '케이씨씨' stock_name, '002380' stock_code, 'KOSPI200 에너지/화학' sector_name from dual union all 
  select '케이씨씨' stock_name, '002380' stock_code, '대형(시가총액)' sector_name from dual union all 
  select '케이씨씨' stock_name, '002380' stock_code, '화학' sector_name from dual union all 
  select '대한화섬' stock_name, '003830' stock_code, '제조업' sector_name from dual union all 
  select '대한화섬' stock_name, '003830' stock_code, '화학' sector_name from dual union all 
  select '대한화섬' stock_name, '003830' stock_code, '소형(시가총액)' sector_name from dual union all 
  select '태광산업' stock_name, '003240' stock_code, '화학' sector_name from dual union all 
  select '태광산업' stock_name, '003240' stock_code, 'KOSPI200지수' sector_name from dual union all 
  select '태광산업' stock_name, '003240' stock_code, 'KOSPI200 에너지/화학' sector_name from dual union all 
  select '태광산업' stock_name, '003240' stock_code, '제조업' sector_name from dual union all 
  select '태광산업' stock_name, '003240' stock_code, '중형(시가총액)' sector_name from dual
)
select stock_name, 
       stock_code, 
       SUBSTR(
        XMLAGG(
            XMLELEMENT(COL ,',', sector_name) ORDER BY sector_name
        ).EXTRACT('//text()').GETSTRINGVAL(), 2
       ) as sector_names
from   base_data
group by stock_name, stock_code
반응형

WRITTEN BY
데르벨준

,