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. for Example,
User Date Events
123 2018-02-13 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
The Output would be something like this
User Event Before After
123 A 1 3
134 A 0 1
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 counter for. Any Suggestions?