在此处添加一个与上面 Topic External Traffic Sources 查询略有不同的变体以供参考。
此版本对 topic_ids 使用了 int_list 参数,因此如果您想为多个 topic_ids 运行查询,可以使用此查询。
-- [params]
-- int_list :topic_ids = 12345
SELECT
ind.name AS domain, -- 外部引荐流量的域名
COUNT(*) AS clicks -- 来自此来源的总点击次数
FROM incoming_links il
INNER JOIN posts p
ON p.deleted_at IS NULL
AND p.id = il.post_id
INNER JOIN topics t
ON t.deleted_at IS NULL
AND t.id = p.topic_id
INNER JOIN incoming_referers ir
ON ir.id = il.incoming_referer_id
INNER JOIN incoming_domains ind
ON ind.id = ir.incoming_domain_id
WHERE t.id IN (:topic_ids) -- 过滤指定的帖子列表
AND ind.name != '127.0.0.1'
GROUP BY ind.name
ORDER BY clicks DESC