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
My guess on (3) is that it’s a time zone issue, and/or that it’s based on the second that you run the script and you want the previous or next midnight. (Not quite sure how to fix either of those offhand).
Not sure if this’ll help but you can try
To get when they’re going to close, you’d need to add something to the SELECT part (which you can infer from the available fields) and change FROM like
FROM topics t, discourse_voting_topic_vote_count dvc, topic_timers tt