1>PersonalDetailClientID (pk)name,surnameemail2> SkillmasterSkillid(pk)skillname3> EndUserenduserid(pk)userid(FK) // perosnaldeail clientidFeesId(FK)4> UserskillDetailsid(PK)ClientId (FK)SkillId(Fk)What I have tried:select PersonalDetails.name,PersonalDetails.phone,PersonalDetails.email,EndUser.Amount,SkillMaster.SkillName from PersonalDetails join EndUser on PersonalDetails.ClientID = EndUser.UserIdjoin Userskilldetail on Userskilldetail.clientId = PersonalDetails.ClientIDjoin SkillMaster on SkillMaster.SkillID = Userskilldetail.Skillidoutputjaydeep444444jay@[email protected] i需要jaydeep作为一个记录,mvc和jquery在一行上用逗号 i requried jaydeep as a one record and mvc and jquery on one line with [email protected],jquery 推荐答案 Create table #temp(name varchar(50),phone int,email varchar(max),amount money, skillName varchar(10));insert into #temp values('jaydeep',444444,'[email protected]',34,'mvc'),('jaydeep',444444,'[email protected]',34,'jquery'),('jaydeepshah',50,'[email protected]',50,'css'),('jaydeepshah',50,'[email protected]',50,'sql');SELECT DISTINCT name,phone,email,Amount,STUFF((SELECT DISTINCT ', '+ SkillName FROM #temp as t1WHERE T1.Name =t2.NameFOR XML PATH(''),TYPE).value('.','NVARCHAR(MAX)') ,1,2,'')AS SkillName FROM #temp t2;------------------------------------------namephoneemailAmountSkillName------------------------------------------jaydeep444444jay@gmail.com34.00jquery, [email protected], sql-------------------------------------------------------------------;WITH X AS( SELECT PersonalDetails.name, PersonalDetails.phone, PersonalDetails.email,EndUser.Amount,SkillMaster.SkillName FROM PersonalDetails INNER JOIN EndUser ON PersonalDetails.ClientID = EndUser.UserId INNER JOIN Userskilldetail ON Userskilldetail.clientId = PersonalDetails.ClientID INNER JOIN SkillMaster ON SkillMaster.SkillID = Userskilldetail.Skillid) SELECT DISTINCT name,phone,email,Amount, STUFF((SELECT DISTINCT ', '+SKL.SkillName FROM X AS SKL WHERE SKL.Name=X.Name FOR XML PATH(''),TYPE ).value('.','NVARCHAR(MAX)') ,1,2,'')AS SkillName FROM X 这篇关于查询给我重复记录我想显示单个记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-21 10:36