简体   繁体   English

如何获取 SQL、Bigquery 中前一天的记录数?

[英]How do I get count of records from previous day in SQL, Bigquery?

As written in the question, I'm trying to get a count of all records from the previous day in Bigquery.正如问题中所写,我试图在 Bigquery 中计算前一天的所有记录。 My column for the times is ingest_time.我的时代专栏是 ingest_time。 I've tried the query below, but it doesn't work in Bigquery.我已经尝试过下面的查询,但它在 Bigquery 中不起作用。 I'm using standard sql in bigquery for this question.对于这个问题,我在 bigquery 中使用标准 sql 。


where 
  date(ingest_time)=date(date_sub(now(),interval 1 day));

Try the following for standard SQL:尝试以下标准 SQL:

SELECT COUNT(*) AS cnt
FROM yourTable
WHERE DATE(ingest_time) >= DATE_ADD(CURRENT_DATE(), INTERVAL -1 DAY);

Just an addition to Tim's answer, you can use COUNTIF operator:只是蒂姆的答案的补充,您可以使用 COUNTIF 运算符:

select 
  COUNTIF(DATE(ingest_time) >= DATE_ADD(CURRENT_DATE(), INTERVAL -1 DAY)) as cnt 
FROM yourTable

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM