Multiple Resources with multiple names
Sorry if this may seem simple, maybe it's Friday and my brain just isn't working. I have been trying to figure out the best way to handle a problem for 4 or so hours and can't come up with the best answer. Hopefully you guys can help me out. I am working with MSSQL
I need to concatenate these "Names" as a single string delimited by commas. And only show the single ID. ie.. |ID1 | name1,name2,name3|.
I have never done this and cannot locate the resources to figure it out. I am sure there is some way you can coalesce it, but I can't figure it out. Thanks for your time in advance.
ID NAME
ID1 NAME1
ID1 NAME2
ID1 NAME3
ID2 NAME2
ID2 NAME3
ID3 NAME1
ID4 开发者_如何学编程 NAME2
SELECT s2._ResourceGuid, s2.SoftwareCount, s2.RPMList FROM (SELECT rpm._ResourceGuid,count(rpm.name) AS SoftwareCount, (???????) as SoftwareList FROM Inv_Unix_RPMInfo rpm WITH (NOLOCK) WHERE rpm.Name ='VRTSvxvm' OR rpm.Name = 'VRTSvxfs'
OR rpm.Name = 'VRTSvcs' GROUP BY _ResourceGuid )s2MySQL has a great non-standard function for this called GROUP_CONCAT
. I found a few articles on how to do this in MSSQL with a quick googling. Here's one now:
How to return multiple values in one column (T-SQL)?
精彩评论