从两行中选择值并在一行中插入一列 [英] Select values from two rows and insert in one row one column
本文介绍了从两行中选择值并在一行中插入一列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有桌面顾客
名称产品
ajay笔
amar铅笔
ajay book >
假包
i想输出
名称产品
ajay pen,book
amar铅笔
假包
I have table customer
name product
ajay pen
amar pencil
ajay book
sham bag
i want output as
name product
ajay pen,book
amar pencil
sham bag
推荐答案
试试这个:
try this:
select Name,
STUFF((select ','+A.Product from Customer A where A.prodid=B.prodid for XML Path('')),1,1,'') as pages
from Customer B group by B.Name
您可以在sql server中使用For XML Path。以下是参考链接。
http:// www .mahipalreddy.com / blog /?p = 79 [ ^ ]
You can use "For XML Path" in sql server. Below is the reference link.
http://www.mahipalreddy.com/blog/?p=79[^]
请参考此 link [ ^ ]
希望这对您有帮助,请让我知道你的更新!!!
快乐编码:)
Please refer this link[^]
Hope that this will help you and please let me know your update !!!
Happy Coding :)
这篇关于从两行中选择值并在一行中插入一列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文