Créé un sujet dans une catégorie spécifique avec des conditions

J’ai essayé ceci pour les utilisateurs qui ont créé un nouveau sujet dans une catégorie spécifique qui remplissait certaines conditions.

SELECT DISTINCT ON (p.user_id) p.user_id, p.id post_id, p.created_at granted_at
FROM posts p
INNER JOIN topics t
ON p.topic_id=t.id
WHERE t.category_id = 99 AND p.post_number=1 AND  <conditions ici> AND
  (:backfill OR p.id IN (:post_ids) )