Requête d'explorateur de données pour tous les utilisateurs actifs (Lurkers + Posteurs)

This should give you every user that have either read whilst logged in or posted over the last year. The data explorer will also print out how many they are.

SELECT p.user_id
FROM posts p
LEFT JOIN topics t ON t.id = p.topic_id
WHERE p.created_at::date > CURRENT_TIMESTAMP - INTERVAL '365 days'
 AND t.deleted_at IS NULL
 AND t.visible = TRUE
 AND t.closed = FALSE
 AND t.archived = FALSE
 AND t.archetype = 'regular'
 AND p.deleted_at IS NULL
UNION
SELECT u.user_id
FROM user_visits u
WHERE u.posts_read > 0
 AND u.visited_at > CURRENT_TIMESTAMP - INTERVAL '365 days'
ORDER BY user_id

There’s probably a more effective way of doing it, but it works :slight_smile: . If you want a specific period you could change > CURRENT_TIMESTAMP - INTERVAL '365 days' (both of them) to something like this: BETWEEN '20200101'::date AND '20210101'::date .

You provided great info and references in your question! I only had to pick the right stuff and combine them.

3 « J'aime »