Tuesday, July 24, 2012

The beauty of LISTAGG

http://www.oracle-base.com/articles/misc/string-aggregation-techniques.php

I have been struggling for a while looking for a way to CHAIN (CONCAT) a column while GROUP BY another column....

Looked into "OVER (PARTITION BY deptno)" ...(oracle analytics)
Looked into STRAGG....

LISTAGG does it in the simplest possible way.

SELECT deptno, LISTAGG(ename, ',') WITHIN GROUP (ORDER BY ename) AS employees FROM emp GROUP BY deptno;

No comments: