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?
t.id as topic_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
Try adding this after the
AND t.id = dvc.topic_id
I didn’t test it, but I think that’s your big problem (fixes the “same topic” problem)
Awesome! Thanks Jay it works
Would you know how to go about the other issues?
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 topics t, discourse_voting_topic_vote_count dvc, topic_timers tt
and add this after
(just like the one you added before).
Thanks again Jay you’re a lifesaver (:
Wow! That worked? That’s awesome. Glad it helped.
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.