rajsTerra New Users by Period
Updated 2023-01-23
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
›
⌄
with users as
(
SELECT
tx_sender,
min(block_timestamp) as date_joined
from terra.core.fact_transactions
group by 1
)
,
new_users as
(
SELECT
date_trunc('{{Granularity}}', date_joined) as date,
case when ('{{Granularity}}' = 'day' and date_trunc('{{Granularity}}', date_joined) = '2023-01-14') or
('{{Granularity}}' = 'hour' and date_trunc('{{Granularity}}', date_joined) = '2023-01-14 18:00:00.000')
then '2. Announcement Date'
when ('{{Granularity}}' = 'day' and date_trunc('{{Granularity}}', date_joined) < '2023-01-14') or
('{{Granularity}}' = 'hour' and date_trunc('{{Granularity}}', date_joined) < '2023-01-14 18:00:00.000')
then '1. Before Announcement Date'
when ('{{Granularity}}' = 'day' and date_trunc('{{Granularity}}', date_joined) > '2023-01-14') or
('{{Granularity}}' = 'hour' and date_trunc('{{Granularity}}', date_joined) > '2023-01-14 18:00:00.000')
then '3. After Announcement Date'
end as period,
count(tx_sender) as no_of_new_users
from users
where date_joined between '{{StartDate}}' and '{{EndDate}}'
group by 1,2
-- order by 1
)
SELECT
period,
avg(no_of_new_users) as no_of_new_users,
(avg(no_of_new_users) - lag(avg(no_of_new_users),2) over (order by period)) / lag(avg(no_of_new_users),2) over (order by period) * 100 as growth_no_of_new_users
from new_users
Run a query to Download Data