Presto取月平均值

Presto take monthly average

主要table

date          merchant_id   number_of_listings
2019-02-01    12            325
2019-02-02    12            332
2019-02-03    12            235
2019-02-04    12            393
2019-02-05    12            484
2019-02-06    12            383
2019-02-07    12            434

输出table

month          merchant_id   average_number_of_listings
2019-02        12            400

这是一个简单的聚合查询。可以用date function date_trunc(),即returns一个月的第一天:

select
    date_trunc('month', date) date_month,
    merchant_id
    avg(number_of_listings) average_number_of_listings
from mytable
group by date_trunc('month', date), merchant_id