Hey so I’ve created a query(at the bottom) that displays topic, category, the vote count of a topic, if its closed, when it was created and the user who has created. If more info is needed please feel free to let me know.
I have a few issues and questions I’d like some help or guidance with since I’m new to sql.
-
When running this query it displays the same topic hundreds of times over. How can I fix this
-
Is there any way to get and show when a topic will auto close?
-
I want only topics within a week to display. But the date_trunc i added shows some items a little over a week ago?
SELECT
t.id as topic_id,
t.category_id,
dvc.votes_count,
t.closed,
t.created_at,
t.user_id
FROM topics t, discourse_voting_topic_vote_count dvc
WHERE t.closed = true
AND t.category_id = 20
AND dvc.votes_count >= 1
AND t.created_at <= date_trunc('week', current_date)::date
AND t.created_at >= date_trunc('week', current_date)::date - 7