这是我当前的 postgres 查询:
sql = """
SELECT
vms.campaign_id,
avg(vms.open_rate_uplift) as open_rate_average,
avg(vms.click_rate_uplift) as click_rate_average,
avg(vms.conversion_rate_uplift) as conversion_rate_average,
avg(cms.incremental_opens),
avg(cms.incremental_clicks),
avg(cms.incremental_conversions)
FROM
experiments.variant_metric_snapshot vms
INNER JOIN experiments.campaign_metric_snapshot cms ON vms.campaign_id = cms.campaign_id
WHERE
vms.campaign_id IN %(campaign_ids)s
GROUP BY
vms.campaign_id
"""
借此,我从 cms 表中获得每个广告系列组的平均增量打开次数、增量点击次数和增量转换次数。但是,我想要 3 个字段的最新值,而不是平均值。请参阅下面的 cms 表屏幕截图 - 我想要给定组的具有最大(即最近)event_id(而不是所有记录的平均值)的记录中的值)。
我怎样才能做到这一点?谢谢