スタッフが解決したトピック

スタッフによって解決されたトピック

指定された期間中にスタッフが解決したトピック数を、カテゴリ別に内訳したものです。カテゴリ配列は、この行を編集することで変更可能です:WHERE t.category_id = ANY ('{46,25,43,40,44,35,22,7,20,17,6,12}'::int[])。クエリを変更して、すべてのカテゴリの結果を返すようにしたり、カテゴリ配列を {1, 2, 3} の形式で文字列パラメータとして渡すようにすることも可能です。

-- [params]
-- int :months_ago = 1

WITH query_period AS (
SELECT
date_trunc('month', CURRENT_DATE) - INTERVAL ':months_ago months' as period_start,
date_trunc('month', CURRENT_DATE) - INTERVAL ':months_ago months' + INTERVAL '1 month' - INTERVAL '1 second' as period_end
)

SELECT
t.category_id,
COUNT(1) AS solved_count
FROM user_actions ua
JOIN topics t
ON t.id = ua.target_topic_id
JOIN query_period qp
ON ua.created_at >= qp.period_start
AND ua.created_at <= qp.period_end
JOIN users u
ON u.id = ua.user_id
WHERE t.category_id = ANY ('{46,25,43,40,44,35,22,7,20,17,6,12}'::int[])
AND ua.action_type = 15
AND (u.admin = 't' OR u.moderator = 't')
GROUP BY t.category_id
ORDER BY solved_count DESC