# מצא משתמשים שחזרו לאחר תקופה

**URL:** <https://meta.discourse.org/t/get-users-who-returned-after-a-period-of-time/225137>\
**Category:** Data & reporting\
**Tags:** sql-query\
**Created:** [24 באפריל,‏ 2022,‏ 7:41am UTC](https://meta.discourse.org/t/get-users-who-returned-after-a-period-of-time/225137 "2022-04-24T07:41:38Z")\
**Posts on this page:** 1\
**Showing post:** 11

<div class="post-metadata">

**Author:** ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)\
**Post date:** [8 ביוני,‏ 2022,‏ 7:20pm UTC](https://meta.discourse.org/t/get-users-who-returned-after-a-period-of-time/225137/11 "2022-06-08T19:20:32Z")

</div>

> [@Senpai](#):
>
> would it be possible to get the `username` instead of the `user_id` from the above SQL query?

Sure, give this a try:

```sql
--[params]
-- integer :days_away = 180
WITH days_between_visits AS (
SELECT
user_id,
visited_at,
LEAD(visited_at) OVER (PARTITION BY user_id ORDER BY visited_at DESC) AS previous_visit,
visited_at - LEAD(visited_at) OVER (PARTITION BY user_id ORDER BY visited_at DESC) AS time_away
FROM user_visits
)

SELECT
username,
dbv.user_id AS id,
visited_at,
time_away
FROM days_between_visits dbv
JOIN users u ON u.id = dbv.user_id
WHERE time_away >= :days_away
ORDER BY visited_at DESC

```

Let me know if you get any timeout errors when running it. Note that I have still included the user’s ID in the results that are returned. That column is now labeled `id`. If you don’t want the ID to be returned, remove the `dbv.user_id AS id,` line from the final SELECT statement.

---

_[View the full topic](https://meta.discourse.org/t/get-users-who-returned-after-a-period-of-time/225137)._
