如何在 presto SQL 中按月分组

How to group by month in presto SQL

我正尝试在 Presto SQL 中按月分组。 我试过这个:

select
    date_trunc('month', CAST(date AS date)) date_month,
    sum(gross_revenue,0) AS 'monthly_net_revenue'
    from gross_revenue_calculator
    group by date_trunc('month', date)

这给了我以下错误: Malformed query: line 61:27: mismatched input ''monthly_net_revenue''. Expecting: <identifier>

预期输出:

October:  2.12
November: .12

你不应该使用单引号作为列名,它要么没有引号要么是双引号,你也可以在 GROUP BY 中按索引引用列,就像在 WITH 子句中一样:

select
    date_trunc('month', CAST(date AS date)) date_month,
    sum(gross_revenue,0) AS monthly_net_revenue
from gross_revenue_calculator
group by 1