Presto:前一个月的最后一天

Presto: Last day of the month prior

我有一个日期列表。我想 return 前一个月的最后一个日期,如下例所示:

date            lastdayofmonthprior
'2018-04-03'    '2018-03-31'

我试过 date_trunc('month', date('2018-04-03'))-1,但是,我得到这个错误:

'-' cannot be applied to date, integer

我猜我无法在 Presto 中对日期进行算术运算。

您可以在 Presto 中使用 DATE_ADD:

DATE_ADD('day', -1, date_trunc('month', date('2018-04-30')))