Skip to content
Advertisement

Isolate/Sum Data Conditionally Based On Event Sequence

I have a table that tracks events sequentially and calculates the time for each event. What I want to do using the below sample data, is calculate the total number of Time Elapse (Seconds) of all Event A’s that happened before the second Event C occurred. So in the below example, I’d want an output of 550 seconds.

Obviously,

returns a result of 750 seconds because it includes event # 6.

Thanks!

Update

Apologies as I just realized something about my data set. There will be an initial Event 1 with EventType C. So, I need to find the second instance rather than the first (so min does not work). I’ve updated the sample table.

Advertisement

Answer

Below is for BigQuery Standard SQL

If to apply to sample data from your questin – result is

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement