sql querry获取数据 [英] sql querry fetch data
本文介绍了sql querry获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好
i有一张桌子tb_product有两列产品和零件号
产品---------- -part_no
1 ------------------ a
1 ----------- ------- b
1 ------------------ c
1 ----- ------------- d
1 ------------------ e
2 ------------------ a
2 ------------------ b
2 ------------------ c
3 --------------- --- a
3 ------------------ b
3 --------- --------- c
i想输出这样的产品
产品-----------部分号
1 ------------------ a,b,c,d,e
2 --- -------------- a,b,c
3 ----------------- a,b,c
请为此输出写一个查询.......
谢谢&安培;问候
Srishti
推荐答案
select distinct product,stuff((select ',' + part_no from TblNm t
where t.product=a.product FOR XML PATH('')),1,1,'') as a
from TblNm as a
快乐编码!
:)
Happy Coding!
:)
试试这个:
Try this:
SELECT t1.[product], STUFF( (SELECT ', ' + [part_no] AS 'text()'
FROM YourTable AS t2
WHERE t2.product = t1.product
FOR XML PATH('')), 1, 1, '') AS [Keywords]
FROM YourTable AS t1
GROUP BY t1.[product]
I t在这里不起作用。
以下是询问者的预期:
1. 首先尝试你想做什么!你可能会发现它并不那么难。
2.制定你所做的事情看似问题/不工作。
尝试一下,告诉你是否面临问题。
各位会员非常乐意为此提供帮助。
It does not work like this here.
Here is what is expected of enquirers:
1. TRY first what you want to do! You may find that it''s not that hard.
2. Formulate what was done by you that looks like an issue/not working.
Try them and tell if you face issues.
Members will be more than happy to help like this.
这篇关于sql querry获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文