if not object_id('Tab') is null
drop table Tab
Go
Create table Tab([Col1] int,[Col2] nvarchar(1))
Insert Tab
select 1,N'a' union all
select 1,N'b' union all
select 1,N'c' union all
select 2,N'd' union all
select 2,N'e' union all
select 3,N'f'
Go
select * from Tab
select Col1,stuff((select ','+Col2 from Tab where Col1=cc.Col1 for xml path('')),1,1,'') as Name from Tab cc group by cc.Col1
SQL for xml path使用
最新推荐文章于 2026-01-06 22:03:14 发布
本文介绍了一个SQL脚本示例,展示了如何创建表、插入数据及进行复杂查询。通过联合与分组子句实现了数据的聚合显示。
2997

被折叠的 条评论
为什么被折叠?



