Concatenate multiple rows into one field

前端 未结 1 660
粉色の甜心
粉色の甜心 2020-12-11 13:29

I have a table with three column like image (Source) and want to write a query that give a table like image (Result)

相关标签:
1条回答
  • 2020-12-11 14:06
    SELECT DISTINCT customer,
        stuff((
                SELECT ',' + cast(policy as varchar(10))
                FROM table1 b
                WHERE a.customerid = b.customerid
                FOR XML path('')
                ), 1, 1, '') [policies]
    FROM table1 a
    
    0 讨论(0)
提交回复
热议问题