Heim >Datenbank >MySQL-Tutorial >一条sql实现字符串分组合并

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-07 17:48:581563Durchsuche

本文章利用一条sql语句实现了将sql表某列多行合为一个值和字符串分组合并功能,有需要的同学可以参考一下下。

 代码如下 复制代码

declare @t table (Id int, Value char(5))
insert into @t
'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

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Vorheriger Artikel:sql max()函数用法Nächster Artikel:mssql中sql各种联合查询