concept event in category churn

This is an excerpt from Manning's book Fighting Churn with Data.
Event—In the context of fighting churn, any user interaction or result that the data warehouse tracks. Events are time-stamped and pertain to a single account or user.
Table 3.2 shows an associated event type table so the string names for events are not duplicated (for performance reasons, as is standard practice in a database or data warehouse.) In summary, an event is something (the event type ID) that happens to someone (the account ID) at some time (the event time). The following additional fields can also be included in such a table but are not required:
event_id—Unique identifiers for events may or may not be included in a data warehouse. It’s not relevant for the analysis because there is normally no uniqueness constraint on events.
Aggregate-count the events by account. If you created the simulated social network dataset, it includes an event for users liking posts. Listing 3.1 shows the query for counting these events, and figure 3.4 illustrates the result. For each account that made any likes within 28 days prior to the metric calculation rate, there is one count.
Figure 3.4 Result of the event count SQL (listing 3.1) on the simulated social network dataset-like event. Your results will differ because the data was randomly simulated.
![]()
Listing 3.1 Counting the number of events in a time window
WITH calc_date AS ( #A SELECT '2020-05-06'::timestamp AS the_date ) SELECT account_id, COUNT(*) AS n_like_permonth #B FROM event e INNER JOIN calc_date d ON e.event_time <= d.the_date #C AND e.event_time > d.the_date - interval '28 day' #D INNER JOIN event_type t ON t.event_type_id=e.event_type_id WHERE t.event_type_name='like' #E GROUP BY account_id; #F