【问题标题】:Concatenating Column Values into a Comma-Separated List in Netezza在 Netezza 中将列值连接到逗号分隔的列表中
【发布时间】:2017-10-13 21:55:08
【问题描述】:

我试图在 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)

谢谢

【问题讨论】:

    标签: netezza


    【解决方案1】:

    一个 group_concat UDF 可以满足您的需求is provided here,并且需要安装在您想要使用它的数据库中。提供的 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)
    

    【讨论】:

    • 有没有办法检查group_concat 是否已安装。试过这个SELECT * FROM _V_FUNCTION where FUNCTION = 'group_concat'; 但没有结果显然SQLEXT.(functions) 不属于该表
    猜你喜欢
    • 2010-11-06
    • 2022-06-10
    • 2013-08-11
    • 1970-01-01
    • 2019-05-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多