0

我的表包含两个字段的详细信息。我想通过 DisplayName 获得独特的详细信息,例如:我想知道如何执行此操作是并行数据仓库/APS,因为 PDW 不支持 FOR XML PATH 函数。

1 编辑、审稿人 7 EIC、编辑、审稿人

  ID      DisplayName
  1        Editor
  1        Reviewer
  7        EIC
  7        Editor
  7        Reviewer
  7        Editor
  19       EIC
  19       Editor
  19       Reviewer

我已经尝试过以下代码,它可以在传统的 SQL Server 上运行,但 APS 不支持“For XML Path”功能。

        SELECT id, displayname = 
     STUFF((SELECT DISTINCT ', ' + displayname
        FROM #t b 
         WHERE b.id = a.id 
      FOR XML PATH('')), 1, 2, '')
      FROM #t a
      GROUP BY id
4

1 回答 1

0

如果您知道要连接的值的数量的固定上限,则以下技术将起作用。

create table test1 (id integer,email varchar(255)) with (heap,distribution=round_robin);

insert into test1 (id,email) values (1,'abc@msn.com');
insert into test1 (id,email) values (1,'xyz@gmail.com');
insert into test1 (id,email) values (2,'efg@xyz.com');
insert into test1 (id,email) values (2,'efg@xyz.com');

select id as Id,concat_ws(',',[1],[2],[3],[4]) as EmailAddresses from (
    select id,[1],[2],[3],[4]
    from (
        select id,row_number() over (partition by id order by email) seq,email from (
            select distinct id,email from test1
            ) as distinctRows
        ) as numberedRows
    pivot (
        max(email) for seq in ([1],[2],[3],[4])
        ) as pivotLookup
    ) as pivotedRows
于 2019-04-23T23:08:39.320 回答