WITH clause allows for chaining queries and controlling the scope of variables passed between query parts. It is especially useful for aggregation, filtering on intermediate results, or renaming fields. Any variable not explicitly passed with WITH is no longer available in the next part of the query.
WITH is used to aggregate the number of events each user has performed,then WHERE is used to filter users who performed more than three events. This pattern is common in analytical queries where results need to be aggregated and filtered.