This is for finding top 10 advertiser apps'(based on # of installs) avg. eCPM (calculation below in query). It works accurately if I run it with one publisher ID only.
Issue: when using more than one publishing app ID, the subquery (C2) reads it as if the top 10 advertiser apps are from multiple publishing IDs, thus misleading calculations. How can I run this in a way that it can read per publisher app (& GET ECPM OF TOP 10 ADVERTISERS PER PUBLISHER APP)?
SELECT
d.app_name AS publisher_app_name,
a.publisher_app AS publisher_app_id,
( SELECT
CASE WHEN SUM(b.impressions) > 0
THEN ROUND((1000*SUM(b.money_spent))/SUM(b.impressions),3)
ELSE 0
END AS top_10_adv_ecpm
FROM warehouse.daily_uber_aggr b
WHERE publisher_app IN ('983234fb17ba470008','2b3ed6ff4d0e48463')
AND b.dt BETWEEN '2018-12-26' AND '2019-01-25'
AND b.advertiser_app IN ( SELECT advertiser_app
FROM warehouse.daily_uber_aggr
WHERE publisher_app IN ('983234fb17ba470008','2b3ed6ff4d0e48463')
AND dt BETWEEN '2018-12-26' AND '2019-01-25'
GROUP BY advertiser_app
ORDER BY SUM (converted_installs) DESC
LIMIT 10
) AS top_10_adv_ecpm,
SUM(a.converted_installs) AS installs_publisher
FROM warehouse.daily_uber_aggr a
LEFT JOIN dimensions.apps d ON d.app_id = a.publisher_app
WHERE a.publisher_app IN ('983234fb17ba470008','2b3ed6ff4d0e48463')
AND a.dt BETWEEN '2018-12-26' AND '2019-01-25'
GROUP BY
d.app_name,
a.publisher_app