postgresql - Aggregating an average -
i trying aggregate average position of digital marketing ads using following query;
insert ad_copies_without_conversions_aggregate ( select "key" ,sum("clicks") "clicks" ,sum("impressions") "impressions", sum("cost") "cost", **sum(("avg. position" * "impressions")* "impressions") "avg. position"** ad_copies_without_conversions_preaggregate group "key");
the average position weighted impressions free calculation between 2 rows follows
key |avg pos|impressions|avg position * impressions| -------+-------+-----------+--------------------------+ abcd |4 |4000 |16000 efgh |2 |5000 |4000 total |6 |9000 |20000
the final calculation applied each unique row should follows;
(column)|avg position * impressions| / impressions
Comments
Post a Comment