# Data Explorer query to identify trust level change dates

**URL:** https://meta.discourse.org/t/data-explorer-query-to-identify-trust-level-change-dates/164037
**Category:** Data & reporting
**Tags:** sql-query
**Created:** [September 14, 2020, 9:11pm UTC](https://meta.discourse.org/t/data-explorer-query-to-identify-trust-level-change-dates/164037 "2020-09-14T21:11:26Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Randy\_Hulett](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/randy_hulett/32/182177_2.png) [@Randy\_Hulett](https://meta.discourse.org/u/Randy_Hulett)
#### Post date: [September 14, 2020, 9:11pm UTC](https://meta.discourse.org/t/data-explorer-query-to-identify-trust-level-change-dates/164037/1 "2020-09-14T21:11:26Z")

</div>

We would like to welcome users when they achieve trust level 3. (We would monitor this periodically through a [Data Explorer](https://meta.discourse.org/t/32566?silent=true) query.)

Does the database contain information on when a user’s trust level changes?  
Or only what the user’s current trust level is?

Thanks,  
Randy

---

<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: [September 15, 2020, 7:33pm UTC](https://meta.discourse.org/t/data-explorer-query-to-identify-trust-level-change-dates/164037/2 "2020-09-15T19:33:29Z")

</div>

> [@Randy\_Hulett](#):
>
> Does the database contain information on when a user’s trust level changes?

Yes, the `group_users` `created_at` field can be used for that. It will be set to the date when the user was added to the group. You could try running a query like the one below at periodic intervals to find all users who were added to the group during the interval. The query’s `granted_at` field expects a date in the form `yyyy-mm-dd`. For example `2020-09-15`

```sql
--[params]
-- string :group_name = trust_level_3
-- date :granted_at

SELECT
user_id,
gu.created_at::date
FROM group_users gu
JOIN groups g
ON g.id = gu.group_id
WHERE gu.created_at::date >= :granted_at
AND g.name = :group_name

```

If you need more user details, it would be possible to update the query to join the `users` table, or the `user_emails` table.

---

<div class="post-metadata">

### Author: ![Randy\_Hulett](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/randy_hulett/32/182177_2.png) [@Randy\_Hulett](https://meta.discourse.org/u/Randy_Hulett)
#### Post date: [September 15, 2020, 8:55pm UTC](https://meta.discourse.org/t/data-explorer-query-to-identify-trust-level-change-dates/164037/3 "2020-09-15T20:55:20Z")

</div>

This works perfectly, @simon.  
Thanks so much!!!

---

<div class="post-metadata">

### Author: ![Shirly\_Nowak](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/shirly_nowak/32/571731_2.png) [@Shirly\_Nowak](https://meta.discourse.org/u/Shirly_Nowak)
#### Post date: [October 26, 2022, 7:29am UTC](https://meta.discourse.org/t/data-explorer-query-to-identify-trust-level-change-dates/164037/4 "2022-10-26T07:29:31Z")

</div>

> [@Randy\_Hulett](#):
>
> We would like to welcome users when they achieve trust level 3. (We would monitor this periodically through a [Data Explorer](https://meta.discourse.org/t/32566?silent=true) query.)

Hi @Randy_Hulett , is this query available somewhere? I am looking to monitor users that achieve TLs 2 and 3 but don’t seem to find the query for that.

---

<div class="post-metadata">

### Author: ![Randy\_Hulett](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/randy_hulett/32/182177_2.png) [@Randy\_Hulett](https://meta.discourse.org/u/Randy_Hulett)
#### Post date: [October 28, 2022, 8:25pm UTC](https://meta.discourse.org/t/data-explorer-query-to-identify-trust-level-change-dates/164037/5 "2022-10-28T20:25:03Z")

</div>

If you join on the `groups` and `group_users` tables as @simon showed, you can add something like this to your WHERE clause:

```plaintext
WHERE gu.created_at::date >= :since
    AND g.name = 'trust_level_3'
    AND u.admin = false

```
