How to get current_date - 1 day in sparksql, same as cur_date()-1 in mysql.
解决方案
The arithmetic functions allow you to perform arithmetic operation on columns containing dates.
For example, you can calculate the difference between two dates, add days to a date, or subtract days from a date. The built-in date arithmetic functions include datediff, date_add,
Out of above what we need is
date_sub(timestamp startdate, int days), Purpose: Subtracts a specified number of days
from a TIMESTAMP value. The first argument can be a string, which is
automatically cast to TIMESTAMP if it uses the recognized format, as
described in TIMESTAMP Data Type. Return type: Returns the date that is > days days before start
and we have
current_timestamp() Purpose: Alias for the now() function. Return
type: timestamp
you can do select
date_sub(CAST(current_timestamp() as DATE), 1)