Filter topics not answered by Staff

Hi Karen,

The query below lists all topics that have not been responded to by the Staff, even if the topic has already received a response from the community.

--[params]
--date :start_date = 2021-01-01
--date :end_date = 2021-12-31

SELECT t.id topic_id, category_id
FROM topics t
WHERE t.deleted_at IS NULL
  AND t.category_id IS NOT NULL
  AND t.created_at::date BETWEEN :start_date AND :end_date
  AND t.id NOT IN (
    SELECT p.topic_id
    FROM posts p 
    JOIN users u ON p.user_id = u.id
    WHERE  u.admin = 't' OR u.moderator = 't'
      AND p.post_number > 1
  )
ORDER BY topic_id DESC
5 Likes