Estadísticas sobre los reportes de spam marcados por la automatización del triaje de IA

Ese error ocurre porque no hubo marcas de spam por parte de @system con las que estuvieras de acuerdo o en desacuerdo durante ese período de tiempo.
La consulta intenta dividir por el número total de marcas que cumplen las condiciones. En tu caso, es 0, así que se rompe.
Si quieres que la consulta siga devolviendo un resultado, puedes usar NULLIF para comprobarlo y obtener NULL cuando no haya nada que dividir.

-- [params]
-- date :start_date = 2025-01-01
-- date :end_date = 2025-05-30

SELECT 
    COUNT(*) AS total_flags,
    COUNT(*) FILTER (WHERE r.status = 1) AS approved_flags,
    COUNT(*) FILTER (WHERE r.status = 2) AS rejected_flags,
    ROUND(100.0 * COUNT(*) FILTER (WHERE r.status = 1) / NULLIF(COUNT(*), 0), 2) AS approved_percentage,
    ROUND(100.0 * COUNT(*) FILTER (WHERE r.status = 2) / NULLIF(COUNT(*), 0), 2) AS rejected_percentage
FROM 
    reviewables r
JOIN 
    post_actions pa ON pa.post_id = r.target_id AND r.target_type = 'Post'
WHERE
    pa.post_action_type_id = 8 -- ID para spam (Marcar como spam y ocultar la publicación)
    AND r.created_at BETWEEN :start_date AND :end_date
    AND r.status IN (1, 2) -- Marcas aceptadas y rechazadas
    AND r.created_by_id = -1 -- ID de usuario del sistema
2 Me gusta