본문 바로가기
스터디/Oracle

[Oracle/오라클] LSITAGG

by 홍장 2021. 7. 16.

SELECT SALES_DT

         , LISTAGG(PRODUCT_NM, ',') WITHIN GROUP (ORDER BY PRODUCT_NM) AS ITEMS

FROM TB_SALES

GROUP BY SALES_DT;

 

LISTAGG에는 중복제거 DISTINCT 사용불가로, 중복값이 조회된다 

SELECT DISTINCT SALES_DT

, LISTAGG(PRODUCT_NM, ',') WITHIN GROUP (ORDER BY PRODUCT_NM)

OVER(PARTITION BY SALES_DT) AS PRODUCT_NM

FROM TB_SALES;

 

 

SELECT LISTAGG(PRODUCT_NM, ',') WITHIN GROUP (ORDER BY PRODUCT_NM) AS ITEMS

FROM (select DISTINCT PRODUCT_NM from TB_SALES);