Skip to content
Advertisement

Tag: sql

Count Distinct IDs in a date range given a start and end time

I have a BigQuery table like this id start_date end_date location type 1 2022-01-01 2022-01-01 MO mobile 1 2022-01-01 2022-01-02 MO mobile 2 2022-01-02 2022-01-03 AZ laptop 3 2022-01-03 2022-01-03 AZ mobile 3 2022-01-03 2022-01-03 AZ mobile 3 2022-01-03 2022-01-03 AZ mobile 2 2022-01-02 2022-01-03 CA laptop 4 2022-01-02 2022-01-03 CA mobile 5 2022-01-02 2022-01-03 CA laptop I want to

SQL Case Statement: Set the default value for an Case

this time I need an explanation for SQL. I have seen on the internet now nothing special and maybe I have a thinking error. I have a case statement and now I want to ” filter ” it in different ways. Specifically I have a question, whether it is possible to provide rows directly with the “ELSE Value” of the

Python how to update a sql server from a dictionary?

I have an INSERT statement that looks like: How do I turn it into an UPDATE statement? I’ve got this so far… Not sure how to join the key/value pairs in the dictionary to make it in the right format. Edit: Answer here is the generated query string that you can use Read More Here

All records with Pivot table

I have table as below after pivoting, I need like, I need to remove all the null values and list like above table. My Query as below, Thanks in advance. Answer Rather than using the modulus three, you should be using the remainder with a divisor of three. But I would avoid PIVOT here and just use a regular aggregation:

get dates periods

it is necessary to get the date periods. input data: expected result: Answer This is a gaps and islands problem. One trick we can use here is to create a pseudo-group which tracks to which island of continuous dates each record belongs. Demo In the first CTE above, the alias cnt gets assigned to a value of 1 whenever the

Advertisement