Skip to content

Using LAG() on an UPDATE with CASE statements

I have a query on a Python Dashboard (using Plotly/Dash) that let users set some variables and update a table in BigQuery. I’m having trouble with one query that has some CASE statements and using LAG(). I wrote the following query: But I got the following error: “Analytic function not allowed in …

How to pivot in BigQuery?

I’m doing validations between source tables and destination tables in different processes in a Data Lake. I work with StandardSQL in BigQuery, and I do the comparisons between both tables with this query: And this is the result: Is there a way to normalize and denormalize this information as follows? I …

Select most recent record (with expiration date)

Let’s say that we have 2 tables named Records and Opportunities: Records: RecordID CustomerID CreateDate 777 1 1/1/2021 888 2 1/1/2021 999 1 2/1/2021 Opportunities: OppID CustomerID OppCreateDate 10 1 12/31/2020 11 1 1/10/2021 12 2 2/1/2021 13 1 4/1/2021 14 1 8/5/2025 Desired Output: RecordID CustomerID…

SQL date interval every 6 months

My SQL Server 2014 table includes a datetime column called CreatedOn. Every day I need to idenfiy companies that were created on this date exactly 6 months ago or a multiple of 6 months ago (i.e 6 …

Update returning * and select result as rows

I want to run a few updates in a single query returning *, and select the output as rows. I currently have That does what I’m looking for but feels like it could be improved. I almost got it working like this but it displays as a single row not two separate rows Answer I think you simply want union