由 Concat Teradata 分组 [英] Group by Concat Teradata

查看:42
本文介绍了由 Concat Teradata 分组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的表有问题,我想使用 group by 来连接字符串字段.我这里有这种情况:

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'

我想得到这个结果:

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

推荐答案

可以尝试使用 xmlagg

You can try using xmlagg

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

这篇关于由 Concat Teradata 分组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆