Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a easy way to get the data with timestamp == yesterday?

Is there a easy way to get the data with timestamp == yesterday?

I just want the data of yesterday.

SELECT
 COUNT(t0.user_id) AS t0_qt_AC5uO9oi
FROM
 `{something here}` AS t0
WHERE
 (t0.event_type = 'XXXXX')
ORDER BY
 t0_qt_AC5uO9oi ASC;

Not sure what is the best way.

like image 488
flashsnake Avatar asked Nov 15 '17 22:11

flashsnake


1 Answers

Below is for BigQuery Standard SQL

#standardSQL
SELECT 
  CURRENT_DATE() today, 
  DATE_ADD(CURRENT_DATE(), INTERVAL -1 DAY) yesterday   

Assuming that you are asking for how to get yesterday's date!
Then of course you need to use it in your query respectively

for example

WHERE t0.event_date = DATE_ADD(CURRENT_DATE(), INTERVAL -1 DAY)
like image 69
Mikhail Berlyant Avatar answered Sep 25 '22 01:09

Mikhail Berlyant