I have a table containing date and events and users. There is event named 'A'. I want to find out how many time a particular event occurred before and after event 'A' in SQL Bigquery. The event A might appear multiple times. But it should count events only till it encounters another event A in both before and after condition.
for Example,
User Date Events
123 2018-02-14 X.Y.A
123 2018-02-12 X.Y.B
134 2018-02-10 Y.Z.A
123 2018-02-11 A
123 2018-02-01 X.Y.Z
134 2018-02-05 X.Y.B
134 2018-02-04 A
123 2018-02-13 A
The output would be something like this.
User Event Before After
123 A 1 1
123 A 0 1
134 A 0 1
The other condition remains same.
This question is an extension of my previous question.
See How to count number of a particular event before another event in SQL Bigquery? for details.
The event that I have to count contains a particular prefix. Means I have to check events that start with ( X.Y.then some event name). So, X.Y.SomeEvent are the events that I have to set the counter for. Any Suggestions?