【问题标题】:SQL server 2012 - convert sales order line data for knime market basket analysisSQL server 2012 - 转换销售订单行数据以进行 knime 购物篮分析
【发布时间】:2018-10-15 20:48:23
【问题描述】:

我正在尝试阅读 knime 中的表格以进行购物篮分析。为此,我需要来自 SQL Server 2012 的销售订单行数据,格式如下:带有空格连接项目的单列。 示例:

ordNo itemNo
x     a1
x     c2
y     a1
y     b4
y     r1

到以下:

col0
a1 c2
a1 b4 r1

【问题讨论】:

    标签: sql sql-server-2012 knime


    【解决方案1】:

    您可以使用FOR XML 子句:

    select distinct stuff ((select distinct ' '+ t1.itemno
                            from table t1
                            where t1.ordno = t.ordno
                            for xml path('')
                           ), 1, 1, ''
                          ) as [col0]
    from table t;
    

    【讨论】:

    • 优秀。谢谢你。这有点慢,但我预料到了。
    • 我也用过 select string = replace(replace(replace('select single spaces',' ',''),'>',' ') 从stackoverflow.com/questions/2455750/… 删除多余的空格。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-23
    • 1970-01-01
    • 2016-01-23
    • 1970-01-01
    • 2022-08-22
    • 1970-01-01
    相关资源
    最近更新 更多