Group by Concat Teradata

耗尽温柔 提交于 2021-01-27 06:05:32

问题


I have a problem with a table, I would like to concat a string field using a group by. I have this situation here:

USER | TEXT
A    | 'hello'
A    | 'by'
B    | 'hi'
B    | '9'
B    | 'city'

I would like to obtain this result:

USER | TEXT
A    | 'hello by'
B    | 'hi 9 city'

回答1:


You can try using xmlagg

SELECT
   User
  ,TRIM(TRAILING ' ' FROM (XMLAGG(TRIM(text)|| ','
                           ORDER BY ColumnPosition) (VARCHAR(1000))))
FROM table
GROUP BY 1


来源:https://stackoverflow.com/questions/46119178/group-by-concat-teradata

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!