Skip to content
Advertisement

Big Query Standard SQL using Partition By with the ARRAY_AGG() function

I am trying to use the PARTITION BY clause with the ARRAY_AGG() function to collapse a column into an array.

My Standard SQL in Big Query is as follows:

My expected output is:

My current output looks something like this taking one date value for example:

You can see the array partitioned by date creates an incremental row for each value of that array.

The dataset that the ARRAY_AGG() function is applied over looks like:

I get the feeling its because I’m grouping by sessions above but that is because I get a validation error like so if I don’t:

Advertisement

Answer

Below is for BigQuery Standard SQL

Just add below around your original query

So, the whole stuff will look like below (and will produce desired result – while preserving your idea of using windowed functions)

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