Skip to content
Advertisement

Aggregrate the variable from timestamp on bigQuery

I am planning to calculate the most frequency part_of_day for each of the user. In this case, firstly, I encoded timestamp with part_of_day, then aggregrate with the most frequency part_of_day. I use the ARRAY_AGG to calculate the mode (). However, I’m not sure how to deal with timestamp with the ARRAY_AGG, because there is error, so my code structure might be wrong

Error received:

Advertisement

Answer

Even though you did not share any sample data, I was able to identify some issues within your code.

I have used some sample data I created based in the formats and functions you used in your code to keep consistency. Below is the code, without any errors:

First, notice that I have changed the column’s name in your ARRAY_AGG() method, it had to be done because it would cause the error “Duplicate column name”. Second, after your TIME_TRUNC() function, it was missing a comma so you could select COUNT(*). Then, within your GROUP BY, you needed to group Request_Timestamp as well because it wasn’t aggregated nor grouped. Lastly, in your last GROUP BY, you needed to aggregate or group time. Thus, after theses corrections, your code will execute without any errors.

Note: the Syntax error: Expected ")" but got identifier "COUNT" at [19:9] error you experienced is due to the missing comma. The others would be shown after correcting this one.

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