# Query esploratore dati per tutti gli utenti attivi (Lurker + Poster)

**URL:** https://meta.discourse.org/t/data-explorer-query-for-all-active-users-lurkers-posters/188343
**Category:** Data & reporting
**Tags:** sql-query
**Created:** [28 Aprile 2021, 10:15am UTC](https://meta.discourse.org/t/data-explorer-query-for-all-active-users-lurkers-posters/188343 "2021-04-28T10:15:08Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![Heddson](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/heddson/32/96742_2.png) [@Heddson](https://meta.discourse.org/u/Heddson)
#### Post date: [29 Aprile 2021, 8:18pm UTC](https://meta.discourse.org/t/data-explorer-query-for-all-active-users-lurkers-posters/188343/2 "2021-04-29T20:18:42Z")

</div>

Questo dovrebbe restituirti tutti gli utenti che hanno letto qualcosa mentre erano connessi o che hanno pubblicato nell’ultimo anno. L’esploratore di dati mostrerà anche il numero totale di tali utenti.

```
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

```

Probabilmente esiste un modo più efficiente per farlo, ma questo funziona 🙂 . Se desideri un periodo specifico, puoi sostituire `> CURRENT_TIMESTAMP - INTERVAL '365 days'` (in entrambi i casi) con qualcosa del genere: `BETWEEN '20200101'::date AND '20210101'::date`.

Hai fornito ottime informazioni e riferimenti nella tua domanda! Ho dovuto solo selezionare gli elementi giusti e combinarli.

---

_[View the full topic](https://meta.discourse.org/t/data-explorer-query-for-all-active-users-lurkers-posters/188343)._
