Skip to content
Advertisement

How can i find rows before a specific value?

I have the next row and what I want to do is to select all the rows before the type “shop”. I tried using case in the “where clause” but I didn’t get any result. How can I do it?

For example, what I want to get is the visitnumber before type = “shop”.

it would be very helpful because what I’m trying to do is to get all the actions that happened before an specific event on big query.

Advertisement

Answer

One method uses correlated subqueries:

However, in BigQuery, I prefer an approach using window functions:

This has the advantage of keeping all ids even those that don’t have a “shop” type.

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