SqlServer使用STUFF拼接内容[通俗易懂]

SqlServer使用STUFF拼接内容[通俗易懂]–插入一下临时数据源 with m as( select '张三' name,'语文'course,'89'score union all selec

SqlServer使用STUFF拼接内容

–插入一下临时数据源

with m as(
select “张三” name,”语文”course,”89″score union all
select “张三” name,”数学”course,”100″score union all
select “张三” name,”英语”course,”40″score union all
select “张三” name,”物理”course,”93″score union all
select “张三” name,”地理”course,”95″score union all
select “张三” name,”化学”course,”80″score union all
select “李四” name,”语文”course,”89″score union all
select “李四” name,”数学”course,”100″score union all
select “李四” name,”英语”course,”40″score union all
select “李四” name,”物理”course,”93″score union all
select “李四” name,”地理”course,”95″score union all
select “李四” name,”化学”course,”80″score
)select * into #info from m

select * from #info

SqlServer使用STUFF拼接内容[通俗易懂]

–STUFF 拼接

select distinct name,
STUFF((
SELECT “|” + course+”=”+score+”分”
FROM #info B
WHERE B.name=A.name FOR XML PATH(“”)), 1, 1, “”) “拼接串”
from #info A

SqlServer使用STUFF拼接内容[通俗易懂]

 

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
转载请注明出处: https://daima100.com/5921.html

(0)
上一篇 2023-04-21
下一篇 2023-04-21

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注