DB/Oracle & tibero
-
DISTINCT와 GROUP BY의 차이DB/Oracle & tibero 2022. 5. 11. 23:57
DISTINCT와 GROUP BY는 공통적으로 중복된 값을 제거하는 방법이다. WITH t AS ( SELECT '과일' AS TYPE, '사과' AS NAME FROM dual UNION ALL SELECT '과일', '레몬' FROM dual UNION ALL SELECT '과일', '사과' FROM dual UNION ALL SELECT '과일', '사과' FROM dual UNION ALL SELECT '채소', '오이' FROM dual UNION ALL SELECT '채소', '당근' FROM dual UNION ALL SELECT '채소', '당근' FROM dual ) SELECT TYPE, NAME FROM t; TYPE NAME 과일 사과 과일 레몬 과일 사과 과일 사과 채소 오이 채소..
-
Group By에서 문자열 합치기DB/Oracle & tibero 2022. 5. 10. 23:32
Oracle -- 버전별 WITH t AS ( SELECT '과일' type, '사과' name, '0' code FROM dual UNION ALL SELECT '과일', '레몬', '1' FROM dual UNION ALL SELECT '과일', '포도', '2' FROM dual UNION ALL SELECT '과일', '참외', '3' FROM dual UNION ALL SELECT '채소', '오이', '0' FROM dual UNION ALL SELECT '채소', '당근', '1' FROM dual UNION ALL SELECT '채소', '호박', '2' FROM dual ) SELECT type , SUBSTR(XMLAgg(XMLElement(x, ',', name) ORDER BY co..