将多行连接成一个字段 [英] Concatenate multiple rows into one field
本文介绍了将多行连接成一个字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个像图像(源)这样的三列的表,想编写一个查询,给出像图像(结果)这样的表
I have a table with three column like image (Source) and want to write a query that give a table like image (Result)
推荐答案
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
这篇关于将多行连接成一个字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文