Skip to content
Advertisement

Tag: google-bigquery

How to check if a value exists in an array type column using SQL?

I am having a bigquery table with many columns including one array type column of zero or many integers. For instance: Using BigQuery SQL, I want to generate another column exists if any value of tuple (3, 10) is included in some_numbers arrays. My desired output: How can I do this? Answer Consider below approach when applied to sample data

Extract date from a column

How to extract date from a string like ‘2:24 PM 6-20-2021’? For example, I have a column called Dates (datatype ‘String’) in the table like below – The output should be Answer How to extract date from a string? If you want to extract date as a date type so you will be able then to use data functions –

Combine 2 sql queries in Bigquery

I currently have two queries that i’ve stitched together using views in Bigquery. I am wondering if there’s a way to combine them into a single query and eliminate the need for multiple views. The first query concatenates a few strings to create a field “id” The second query de-dupes the records based on the id field. thank you in

Split large texts into chunks in separate rows

I have a table, where some texts are atrociously big. I want to make sure every row in the query output does not exceed, say, 100.000 characters. How do I do that? Here is a quick sample: Let’s say I want output text column to be less than 10 characters. So, I need this result: It would be even better

How to convert X items into array and looping

I have a table with 100k records. I want to create an array for each 10k items and loop this, i.e. first 10k items-> array(first 10k items), then seconds array(10k different items), then third and so on. In other words, each array contains 10k different records. This is what I tried: This is the error I get: Query error: SELECT

BigQuery: How to aggregate records in a STRUCT or JSON field?

I want to aggregate a pair of columns as a dictionary of key,value pairs to construct a STRUCT or a JSON STRING over multiple records. Currently my implementation leverages the STRING nature of JSON & STRING_AGG to build such a JSON value: Which results in the following: Is there a more readable approach? Kind of a STRUCT_AGG(key_field STRING, value_field )

Counting unique values within a time window

I have data that looks like (over 100.000 rows): What I would like: Explanation CONTEXT I want to find out how many people (person) are working in the same location (Location) by looking at a time window (timestamp) of max 10 minutes and checking whether a person is really working simultaneously or just taking over their shift within that frame.

Date formatting from BigQuery to Data Studio

I’m trying to connect Google Analytics data from BigQuery for visualization in Data studio; I can’t get the date formatted in a readable format in data studio. I’ve tried using this reg expression: but i still can’t get it to work. The text format is ‘20210921’ Answer Use parse_date(‘%Y%m%d’, date) another option is cast(date as DATE format(‘YYYYMMDD’))

Advertisement