当前位置:数据库 > SQLServer >>

一条sql实现字符串分组合并

 代码如下 复制代码

declare @t table (Id int, Value char(5))
insert into @t
select '1','09:01' union
select '1','12:05' union
select '2','08:04' union
select '2','17:09' union
select '3','99888'


select * from @t
select id,stuff((select ','+rtrim(value)
from @t
where id=a.id for xml path('')
),1,1,'') as [values]
from (select distinct id from @t) a

补充:数据库,Mssql 
Oracle
MySQL
Access
SQLServer
DB2
Excel
SQLite
SYBASE
Postgres
如果你遇到数据库难题:
请访问www.zzzyk.com 试试
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,