--[params]
-- date :start_date
-- date :end_date
WITH group_mentions AS (
SELECT
split_part(url, '/', 3) AS group_name
FROM topic_links tl
JOIN topics t ON t.id = tl.topic_id
WHERE internal = true
AND url LIKE '/groups/%'
AND t.deleted_at IS NULL
AND t.archetype = 'regular'
AND tl.created_at::date BETWEEN :start_date AND :end_date
)
SELECT
gm.group_name,
COUNT(gm.group_name) AS mention_count
FROM group_mentions gm
JOIN groups g ON g.name = gm.group_name
WHERE g.created_at::date <= :start_date
GROUP BY gm.group_name
ORDER BY mention_count DESC
该查询仅返回添加到常规帖子中的提及(但会包含添加到私密帖子中的提及)。如果您希望将添加到私信中的提及也包含在结果中,请从第一个查询中删除 AND t.archetype = 'regular' 这一行。