仪表板报告 - 帖子

是的,您可以使用以下查询:

--[params]
-- date :start_date
-- date :end_date
-- null category_id :category_id 
-- null user_id :user_id
-- boolean :include_subcategories = false

SELECT 
    u.username AS "用户",
    p.created_at::date AS "日期",
    COUNT(p.id) AS "计数"
FROM posts p
INNER JOIN topics t ON t.id = p.topic_id AND t.deleted_at IS NULL
INNER JOIN users u ON p.user_id = u.id
LEFT JOIN categories c ON t.category_id = c.id
WHERE p.created_at::date BETWEEN :start_date AND :end_date
    AND p.deleted_at IS NULL
    AND t.archetype = 'regular'
    AND p.post_type = 1
    AND (
        :category_id IS NULL 
        OR t.category_id = :category_id
        OR (:include_subcategories AND c.parent_category_id = :category_id)
    )
    AND (:user_id IS NULL OR p.user_id = :user_id)
GROUP BY u.username, p.created_at::date
ORDER BY p.created_at::date ASC, u.username

参数:

  • :start_date & :end_date: 定义报告时间范围(必需)
  • :category_id: 过滤特定类别的可选参数
  • :user_id: 过滤特定用户的可选参数
  • :include_subcategories: 包含所选类别子类别的选项

此查询显示:

  • 用户: 帖子作者的用户名
  • 日期: 帖子创建的日历日期
  • 计数: 该用户在该日期创建的帖子数量

示例数据:

用户 日期 计数
user 1 2023-01-01 3
user 2 2023-01-01 2
user 3 2023-01-01 1
user 1 2023-01-02 2
user 2 2023-01-02 3
user 1 2023-01-03 1
2 个赞