# Статистика пользователя плюс электронная почта

**URL:** <https://meta.discourse.org/t/user-stats-plus-email/317793>\
**Category:** Data & reporting\
**Tags:** sql-query\
**Created:** [17.Июль.2024 17:16:51 UTC](https://meta.discourse.org/t/user-stats-plus-email/317793 "2024-07-17T17:16:51Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![Heather13](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/heather13/32/203449_2.png) [@Heather13](https://meta.discourse.org/u/Heather13)\
**Post date:** [17.Июль.2024 17:16:51 UTC](https://meta.discourse.org/t/user-stats-plus-email/317793/1 "2024-07-17T17:16:51Z")

</div>

> [@User posts by email domain over last 7 days](https://meta.discourse.org/t/user-posts-by-email-domain-over-last-7-days/304560/4?u=jammydodger):
>
> I think it actually gives inflated numbers due to the group joins (also, everyone is part of an automatic group for their trust level, so there’s a bit of inconsistency there). I think we can strip out those and maybe add a couple of tweaks to zone in topics, posts, and PMs. Let me have a bash. Maybe something like this: -- [params] -- string :interval = 7 days SELECT split\_part(ue.email, '@', 2) AS email\_domain, -- Extracts the domain part of the email COUNT(p.id) AS "Total Posts", …

Как мне добавить столбцы для времени чтения, количества прочитанных постов и посещений пользователя в этот запрос?

По сути, я хотел бы объединить следующий запрос с тем, который вы опубликовали здесь, а также добавить время чтения (если это возможно):

```plaintext
select user_id,
    count(1) as visits,
    sum(posts_read) as posts_read
from user_visits
where posts_read > 0
and visited_at > CURRENT_TIMESTAMP - INTERVAL '7 days'
group by user_id
order by visits desc, posts_read desc

```

Примечание: Я предпочитаю возможность задавать параметр интервала так, как это сделано в вашем запросе, но хотел бы, чтобы пользователь в запросе, который я отправил, указывался по полному адресу электронной почты (а не только по домену).

Я новичок в написании запросов, понимаю параметры и смог модифицировать ваш запрос так, чтобы он использовал полный адрес электронной почты. Однако мне не удается объединить столбцы посещений и прочитанных постов из моего запроса, а также добавить время чтения.

---

_[View the full topic](https://meta.discourse.org/t/user-stats-plus-email/317793)._
