Skip to content
Advertisement

How to get “session duration” group by “operating system” in Firebase Bigquery SQL?

I try to get the “average session duration” group by “operating system” (device.operating_system) and “date” (event_date).

In the firebase blog, they give us this query to get the average duration session

This query give me the total user engagement by user ID (each row is a different user):

But I have no idea where I have to add the “operating system” and “event_date” variables to get this information by os and date. I tried differents queries with no result. For example to get this result by operatiing system I tried the following

But it gives me an error message (Error: Unrecognized name: device at [9:10] ). In others queries device.operating_system is recognized.

For example in that one :

What I would like to have as a result is something like this :

Thank you

Advertisement

Answer

The error is probably because you are referencing the variable device in the outer query, while this variable is only visible from the inner query (subquery). I believe the issue will be fixed by changing the last row of the query from GROUP BY device.operating_system to GROUP BY operating_system.

Hopefully this will make clearer what is happening here: the inner query is accessing the table FIREBASE_PROJECT and returning the field operating_system from the nested column device. The outer query accesses the results of the inner query, so it only sees the returned field operating_system, without information about its original context within the nested variable device. That is why trying to reference device at this level will fail.

In the other example you posted this issue does not appear, since there is only a simple query.

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