Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- WITH rev AS (
- SELECT log_date,
- utm_source,
- SUM(CASE WHEN name = 'ads_rev' THEN CAST(object_value AS FLOAT) ELSE 0 END) AS revenue,
- COUNT(DISTINCT user_id) AS dau
- FROM events_log
- WHERE log_date BETWEEN '2022-11-30' AND '2022-12-05'
- GROUP BY log_date, utm_source
- ),
- mean_rev AS (
- SELECT utm_source,
- SUM(revenue) AS ads_rev,
- AVG(dau) AS mean_dau,
- AVG(revenue / CAST(dau AS FLOAT)) AS mean_arpdau
- FROM rev
- GROUP BY utm_source
- )
- SELECT * FROM mean_rev
- ORDER BY mean_arpdau DESC
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement