Skip to content

Tag: google-bigquery

Calculate number of times a user visited a page in SQL

I have table as shown below. It has 3 columns user, page and timestamp. In the above table I want to calculate number of times a user visits a particular page. Each record in the above table is a hit, so just grouping by column page wont help. I essentially want to count continuous records for a particular pa…

Adding all dates to SQL query for grouped dates

I would like SQL to return all dates, whether or not they are null or 0 from the following query: Current Output: Desired Output: I do not have another table with dates to reference My min should be the first date pulled from the query (in this case, 01/02/22) and then my max should be the most recent date th…

Why is json_extract_scalar returning null

I have a fairly simple string-formatted json column in a BigQuery database I am trying to flatten. id relationships 1 {‘ownerObject’: {‘data’: None}, ‘investmentObject’: {‘data’: {‘type’: ‘assets’, ‘id’: ’40’}}, &#…

Hierarchy Queries in BigQuery

I have a data from ControlM (scheduler) this way I saw many solutions where they have started from first node and descended to last node. But that is likely to fan-out with this data. What I am looking for a fan-in solution, where I can start with any end node and come towards first node In this case the answ…

Can a Wildcard Search Be Performed Amongst Fields

Always grateful for the infinite wisdom from everyone on this site. I deal with some massive databases that are often difficult to search in. One of which is a lead database with over 1.4k columns and 3 million records. Sometimes, I just want to query to see if a certain value exists anywhere in the database …

Inner join with special conditions

Given an hourly table A with full records, e.g.: And a subset B of it, e.g. I want to keep only those records from A that are in B or at most 2hr behind the B subset, without duplication, e.g. How can the result be achieved with an inner join, without duplication (in this case the hours 8&9) and preservin…