Advertisement
a_khuzina

Untitled

Aug 13th, 2024
314
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 0.58 KB | None | 0 0
  1. WITH rev AS (
  2.  
  3.     SELECT log_date,
  4.            utm_source,
  5.            SUM(CASE WHEN name = 'ads_rev' THEN CAST(object_value AS FLOAT) ELSE 0 END) AS revenue,
  6.            COUNT(DISTINCT user_id) AS dau
  7.     FROM events_log
  8.     WHERE log_date BETWEEN '2022-11-30' AND '2022-12-05'
  9.     GROUP BY log_date, utm_source
  10.  
  11. ),
  12. mean_rev AS (
  13.  
  14.     SELECT utm_source,
  15.            SUM(revenue) AS ads_rev,
  16.            AVG(dau) AS mean_dau,
  17.            AVG(revenue / CAST(dau AS FLOAT)) AS mean_arpdau
  18.     FROM rev
  19.     GROUP BY utm_source
  20.  
  21. )
  22. SELECT * FROM mean_rev
  23. ORDER BY mean_arpdau DESC
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement