'How do I find yesterday's date

I'm stuck on a query regarding dates in Big Query using SQL. I have a table that consists of customer_id (int), date_purchase (date), sales (int).

The query is to find all customer_id and date_purchase with lower sales in comparison the the previous date_purchase (yesterday).

I've tried using the following statement: DATE_SUB(date_purchase,interval 1 day), however this also creates dates that don't exist in the database.

Any help will be appreciated! Thanks



Solution 1:[1]

In Bigquery you can directly use (date- 1) to get previous date. Below is example enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Vishal Bulbule