"Is there any way to get the data between current date to yesterday date via query in Bigquery"

"Is there any way to get the data between current date to yesterday date via query in Bigquery"

"I am using query for getting data from current date to yesterday date in Bigquery but i am not able to get the yesterday date in BQ"

SELECT COUNT (*) 
FROM `urbn-edw-prod.UrbnProcessingErrors.RetailFeedDimensionError` 
WHERE errorReason = "Invalid Merchandise SKUs" 
AND DATE(ingestionTime) between CURRENT_DATE and DATE_ADD(CURRENT_DATE(), INTERVAL -1 DAY)

我认为这行代码没有给出昨天的日期

DATE_ADD(CURRENT_DATE(), INTERVAL -1 DAY)

我想在 BQ 中获取从今天到昨天的数据,但我想我使用了错误的查询我希望现在输出为 500 但它给出了 0

您可以使用:

WHERE errorReason = 'Invalid Merchandise SKUs' AND
      DATE(ingestionTime) >=  DATE_ADD(CURRENT_DATE(), INTERVAL -1 DAY) AND
      DATE(ingestionTime) < CURRENT_DATE())

或者更简单地说:

WHERE errorReason = 'Invalid Merchandise SKUs' AND
      DATE(ingestionTime) = CURRENT_DATE())

当您使用 BETWEEN 时,最后两个操作数的顺序很重要。数值小的在前,数值大的在后

I expect output to be 500 for now but it is giving 0

这是因为你在下一行的顺序有误

AND DATE(ingestionTime) between CURRENT_DATE and DATE_ADD(CURRENT_DATE(), INTERVAL -1 DAY)   

你应该使用

AND DATE(ingestionTime) between DATE_ADD(CURRENT_DATE(), INTERVAL -1 DAY) and CURRENT_DATE    

this line of code is not giving yesterday date i think

DATE_ADD(CURRENT_DATE(), INTERVAL -1 DAY) 昨天给你 - 问题如上文所述 - 但是,你也可以使用下面的

DATE_SUB(CURRENT_DATE(), INTERVAL 1 DAY)    

另请注意,当您使用 BETWEEN 时 - 它的两边都包含在内,因此如果您只需要今天的数据,您可以使用

AND DATE(ingestionTime) = CURRENT_DATE     

或者就在昨天 - 你可以使用

AND DATE(ingestionTime) = DATE_ADD(CURRENT_DATE(), INTERVAL -1 DAY)