id name
1 a
1 b
1 c
2 d
2 e

parent children
1 a,b,c
2 d,e
3 f

WITH    t AS ( SELECT   1 parent ,
                        'a' child
               UNION
               SELECT   1 ,
                        'b'
               UNION
               SELECT   1 ,
                        'c'
               UNION
               SELECT   2 ,
                        'd'
               UNION
               SELECT   2 ,
                        'e'
               UNION
               SELECT   3 ,
                        'f'
             )
    SELECT  parent ,
            STUFF(( SELECT  ',' + child
                    FROM    t a
                    WHERE   b.parent = a.parent
                  FOR
                    XML PATH('')
                  ), 1, 1, '') children
    FROM    t b
    GROUP BY b.parent

 

相关文章:

  • 2021-12-27
  • 2022-12-23
  • 2022-01-29
  • 2021-08-07
  • 2021-07-19
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-11-22
  • 2022-12-23
  • 2022-12-23
  • 2021-09-01
  • 2022-12-23
相关资源
相似解决方案