Getting rid of date filter on BigQuery? - google-bigquery

I'm trying to get rid of this particular date filter on BQ and have a date column instead (kindly check the red circle to see what I'm talking about)
This data was extracted from Microsoft (Bing) Ads using Supermetrics. Any idea how to tackle this? Let me know if you need more information. Thank you.
AK

So the string depicted in the red circle is part of the table name i.e. 2021111.
So to view all the data you will want to create a query that looks at all the tables like, but be careful as datasets can get BIG fast.
SELECT *
FROM `BINGADS_AGE_GENDER_*`
If you wanted to only combine a certain date range you could use
SELECT *
FROM `BINGADS_AGE_GENDER_*`
WHERE _table_suffix BETWEEN '20211001' and '20211101'
If you use this datasource within datastudio you can use the #DS_START_DATE and #DS_END_DATE parameters with the date picker.

Related

Different results BigQuery and Tableau

Hello guys when i try to calculate median and average in my BigQuery and Tableau i get different results even though I am using same numbers and rows. Is there something I should know?
For example;
In BiQuery
select district, avg(sales) from table name
In Tableau
Using district as dimension and select average of sales from the maxcard drop down menu.
Surprisingly the output from the two are not the same.
Any one knows what might be a problem that I should know?
Thanks!
Hi matt_black just got the solution, because in Tableau i made a join with polygon data when this happens it duplicates the data in the Tableau hence different results.

Replacing incorrectly entered dates in sql server

I have ran a query is SQL server. there is a name category and every category has a date that it started... however sometimes data was incorrectly entered in the front end so when I do the data pull it returns two start dates per category when in reality just the earliest date should be present. is there any sql code I can throw into this join query that replaces all situations when a category has two dates with the earliest one?
From what I understand, you need to use the MIN() function to get only the earliest entered event when querying your table. You can achieve this my using something similar to the following:
SELECT
categoryName,
MIN(categoryDate)
FROM Category
GROUP BY categoryName
However, I am not sure this is what you need since we have no dataset to verify against. Ideally, you can explain in a more clear way, what you need to achieve, and we can help you better.

How to count a phrase in Big Query view

I have fir-ui-af***:firestore_export dataset in my BigQuery project.
In this dataset, I have speech_raw_changelog table and speech_raw_latest view.
This is schema of speech_raw_latest view.
In data field which I marked with a red pen, there is JSON data.
This is an example of field and value in data.
I would like to count the number of ******ka#gmail.com in email field in this speech_raw_latest view.
I searched the Internet and found that I should use COUNT function, but I don't know how to use it to solve my problem.
Could you give me any advice, please?
Below is for BigQuery Standard SQL
SELECT COUNTIF(JSON_EXTRACT_SCALAR(data, '$.email') = 'ka#gmail')
FROM `project.dataset.speech_raw_latest`

Remove One Month Data from a BigQuery Table via Query

I am trying to Remove data from One month (July) but I can't manage to write properly the SQL query in the console.
I have tried the following code and worked fine. I just need to find to way to write the range of one complete month (July).
DELETE
FROM Sandbox.SandboxTable
where Date = '2018-12-09T00:00:00'
I have tried different possibilities but had syntax errors. I will strongly appreciate any help!
DELETE
FROM Sandbox.SandboxTable
where
Date >= '2018-07-01T00:00:00' AND Date <= '2018-07-31T23:59:59'

Open Date Frame for BigQuery View (StandardSQL)

I'm trying to create a view with StandardSQL that will automatically have the most updated data every time you open it (BigQuery creates a file with the traffic data per day with the date in the name extension).
I'm using something like
FROM `whatever.ga_sessions_201*` as GA WHERE _TABLE_SUFFIX BETWEEN '70101' AND '81231'
Even though this works when I wanna run the query normally, it does not when I try to create a view with it. I guess I could use a scheduled query but was wondering if there is any way to build a view with an open date frame (just like views work on Athena if the files are correctly uploaded to the S3 bucket you are pointing at).
Thanks in advance!
You could do something like this:
WITH CTE AS
(SELECT max(_TABLE_SUFFIX) tableSuffix
FROM `projectname.dataset.table_*`)
SELECT *
FROM `projectname.dataset.table_*`
join CTE ON _table_suffix = tableSuffix
Might be expensive with lots of tables though?
Might be better to use a WHERE statement and calculate the date you need from the current_date but I appreciate the GA tables don't always arrive at a set time.