我有一个查询,它返回有关工作委员会的分析风格信息以及申请人来自以下结构的位置:
要访问的查询是:
SELECT g.name AS [Source]
,SUM(CASE WHEN v.cost = 0 THEN 1 ELSE 0 END) AS [Organic Clicks]
,SUM(CASE WHEN v.cost <> 0 THEN 1 ELSE 0 END) AS [Paid Clicks]
,COUNT(v.id) AS [Total Clicks]
,SUM(CASE WHEN a.applicant = 1 AND v.cost = 0 THEN 1 ELSE 0 END) AS [Organic Applicants]
,SUM(CASE WHEN a.applicant = 1 AND v.cost <> 0 THEN 1 ELSE 0 END) AS [Paid Applicants]
,SUM(CASE WHEN a.applicant = 1 THEN 1 ELSE 0 END) AS [Total Applicants]
,SUM(v.cost/100.0) AS [Spend]
FROM a_views v
LEFT OUTER JOIN a_views a
ON v.viewerid = a.viewerid
AND v.sessionsourceid = a.sessionsourceid
AND a.applicant = 1
JOIN a_sources s
ON v.sourceid = s.id
JOIN a_sourcegroups g ON s.fk_sourcegroup = g.id
--JOIN jobs j ON v.jobid = j.anal_id AND j.featured = 1
WHERE v.hostName = @jobboard
AND v.viewed_at >= @start AND v.viewed_at <= @end
GROUP BY g.name
唯一的问题是在LEFT OUTER JOIN a_views
块中可能返回多条记录。我需要做的是只在Click
总和中跟踪一次记录,但每次都为Applicant
总和找到它。
我确实在这个问题上发现了一个类似的问题,但回答者实际上并没有提供太多信息。
为了恢复我需要的内容,连接右侧的每个记录实例,但左侧只有一个记录实例。