Created
June 6, 2014 20:20
-
-
Save gowon/e287d3e294e4645bf390 to your computer and use it in GitHub Desktop.
Aggregating Strings in DB2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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