How to use GROUP BY to concatenate strings in SQL Server?

前端 未结 20 2517
无人及你
无人及你 2020-11-21 04:33

How do I get:

id       Name       Value
1          A          4
1          B          8
2          C          9

to

id               


        
20条回答
  •  粉色の甜心
    2020-11-21 04:50

    Let's get very simple:

    SELECT stuff(
        (
        select ', ' + x from (SELECT 'xxx' x union select 'yyyy') tb 
        FOR XML PATH('')
        )
    , 1, 2, '')
    

    Replace this line:

    select ', ' + x from (SELECT 'xxx' x union select 'yyyy') tb
    

    With your query.

提交回复
热议问题