以防其他人需要,在此留下完整的查询:
select ua.user_id, u.username, sum(action_type) actions, sum(case action_type when 5 then 1 else 0 end) replies from user_actions ua
join users u on u.id = ua.user_id
join topics t on target_topic_id = t.id
where ua.created_at > 'YYYY-MM-DD'::date and t.category_id = CATEGORY_ID
group by ua.user_id, u.username;
只需将 YYY-MM-DD 替换为您的截止日期,将 CATEGORY_ID 替换为您的类别 ID。
结果将显示 user_id、username、actions 和 replies。