您的位置:首页 > 博客中心 > 数据库 >

SQL多行合并成一行

时间:2022-03-14 04:28

with cte as(
select groupname,GroupId from Sys_Group where GroupId in(
select ReleaseRangeId from Sys_Notice_Permission where ReleaseRangeType=2 and NoticeId=20)
)

select LEFT(groupname,LEN(groupname)-1) as groupname,
LEFT(GroupId,LEN(GroupId)-1) as GroupId

from
(
SELECT (SELECT groupname+‘,‘ from cte FOR XML PATH(‘‘) ) as groupname,
(SELECT cast(GroupId as nvarchar)+‘,‘ from cte FOR XML PATH(‘‘) ) as GroupId

) A

热门排行

今日推荐

热门手游