Skip to content

Instantly share code, notes, and snippets.

@gowon
Created June 6, 2014 20:20
Show Gist options
  • Save gowon/e287d3e294e4645bf390 to your computer and use it in GitHub Desktop.
Save gowon/e287d3e294e4645bf390 to your computer and use it in GitHub Desktop.
Aggregating Strings in DB2
-- Based on https://www.ibm.com/developerworks/community/blogs/SQLTips4DB2LUW/entry/aggregating_strings42?lang=en
SELECT
dept,
SUBSTR(XMLCAST(XMLGROUP(',' || name AS a
ORDER BY name)
AS VARCHAR(60)), 2) AS Names,
avg(salary) as avgsal
FROM emp
GROUP BY dept;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment