The result of this query is a list of user events for the last 2 days sorted by the amount of times the event was performed.
with last_ev as (select distinct devtodevid, max(eventtime) as eventtimefrom p104704.custom_events where created >= current_date - interval '2 days'group by1)selectname, count(distinct devtodevid)from (select distinct q1.devtodevid, namefrom p104704.custom_events q1 join last_ev q2 using (devtodevid, eventtime)) q3group by1order by2desc
Example 2
The result of this query is a list of last user events before they churn. The churn period is specified.
with last_ev as (select distinct devtodevid, max(eventtime) as eventtimefrom p104704.custom_events ev join p104704.users us using(devtodevid)where us.lasttime <= current_date - interval '7 days'-- churn periodand ev.created >= current_date - interval '30 days'group by1)selectname, count(distinct devtodevid)from (select distinct q1.devtodevid, namefrom p104704.custom_events q1join last_ev q2 using (devtodevid, eventtime)) q3group by1order by2desc
Example 3
The result of this query is a timestamp of the last event with numeric value.
select tm(eventtime) as"event timestamp", datafrom p104704.user_property_updates wheredata::text SIMILAR TO'%customUserProperyName":\d%'order by eventtime desclimit1
The result of this query is a timestamp of the last event with text (string) value.
select tm(eventtime) as"event timestamp", datafrom p104704.user_property_updateswheredata::text SIMILAR TO'%customUserProperyName":"%'order by eventtime desclimit1
Example 4
Use this query to find the users with decreasing player level (events with decreasing player level alert). The result of this query is a list of users and their previous and current levels.
select devtodevid, prev_event_lvl, cur_event_lvlfrom(select devtodevid , lag(eventlevel,1) over (partitionby devtodevid order by eventtime) as prev_event_lvl , eventlevel as cur_event_lvlfrom p104704.levelupswhere created >= current_date - interval '7 day'and eventtime < current_date) twhere prev_event_lvl > cur_event_lvlorder by devtodevid
Example 5
Use this query to calculate user retention. The result of this query is a table that contains the number of new users per day and the number of returning users on the 0th, 1st, 2nd, 3rd, 7th, and 14th day after installation.
withreturnas (select created::dateas date_, count(devtodevid) filter (where retentionday =0) as R0,count(devtodevid) filter (where retentionday =1) as R1,count(devtodevid) filter (where retentionday =2) as R2,count(devtodevid) filter (where retentionday =3) as R3,count(devtodevid) filter (where retentionday =7) as R7,count(devtodevid) filter (where retentionday =14) as R14from p102968.returns_by_24h where created::date>= current_date - interval '1 month'and eventtime >= current_date - interval '1 month'group by1 ), us as (select created::dateas date_, count(1) AS regsfrom p102968.userswhere created::date>= current_date - interval '1 month'group by1 )select us.date_, regs, r0, r1, r2, r3, r7, r14from us left joinreturn r on us.date_=r.date_order by1