我试图在Netezza中进行列值连接,并在sql-server
中找到以下内容Concatenating Column Values into a Comma-Separated List
但它对Netezza不起作用。
有没有解决方案?
我试过的是
SELECT LEFT(COLUMN_NAME, LENGTH(COLUMN_NAME) - 1)
FROM (
SELECT COLUMN_NAME + ', '
FROM information_schema.columns
WHERE table_name IN ('Employee')
FOR XML PATH ('')
) c (COLUMN_NAME)
由于
答案 0 :(得分:1)
执行您想要的is provided here的group_concat UDF,需要安装在您想要使用它的数据库中。提供的tar文件有一个安装脚本,可以为您执行此操作。安装看起来像这样:
$ ./install testdb
CREATE AGGREGATE
Created uda
Done
CREATE AGGREGATE
Created uda
Done
用法看起来像这样:
TESTDB.ADMIN(ADMIN)=> select * from test_gc order by col1, col2;
COL1 | COL2
------+------
1 | A
1 | B
1 | C
2 | C
2 | D
2 | E
(6 rows)
TESTDB.ADMIN(ADMIN)=> select col1, group_concat(col2,',') from test_gc group by col1 order by col1;
COL1 | GROUP_CONCAT
------+--------------
1 | A,B,C
2 | C,D,E
(2 rows)