我为特定的逻辑使用多个联接,但是遇到了问题。其中一些表中的记录具有1-2关系,这使我的输出混乱。我想合并所有这些字符串,以便将其显示为一条记录,但是我不知道如何在sql server中进行操作。在oracle和MySQL中,这很容易,但是我尝试使用在线示例,但失败了。
我的查询:
SELECT c.customerName,c.Guid,p.campaignTitle ,
(SELECT k.campaignTitle FROM [DEV_TEST2].[dbo].campaigns l JOIN [DEV_TEST2].[dbo].campaignstitle k on k.campaignname = l.campaignname where l.campaignid = t.referrerurl) as Referrertitle,
t.activitydate,t.type
FROM [DEV_TEST2].[dbo].campaignknowncustomers c
join [DEV_TEST2].[dbo].[CampaignCustomerMatch] t ON(c.guid = t.visitorexternalid)
join [DEV_TEST2].[dbo].campaigns s ON(t.url = s.campaignid)
join [DEV_TEST2].[dbo].campaignstitle p on(s.campaignname = p.campaignname)
order by customername,activitydate
我的问题是与Campaigntitle列和Referrertitle相关的查询。两者都来自同一张桌子。我需要合并它,并且每个“客户名称,guid,活动日期”仅显示1行