Advertisement
pmkhlv

Untitled

Apr 17th, 2022
1,400
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. with i as (
  2. select
  3.         client_id,
  4.         DATE(MIN(case when action = 'visit' then hitdatetime else null end)) as fst_visit_dt,
  5.         DATE(MIN(case when action = 'registration' then hitdatetime end)) as registration_dt,
  6.         MAX(case when action = 'registration' then 1 else 0 end) as is_registration
  7. from
  8.         user_activity_log
  9. group by
  10.         client_id
  11.     ),
  12.     y as (
  13. select
  14.         client_id,
  15.         SUM(payment_amount) as total_payment_amount
  16. from
  17.         user_payment_log upl
  18. group by
  19.         client_id
  20.     )
  21.  
  22. select
  23.     ua.client_id,
  24.     ua.utm_campaign,
  25.     i.fst_visit_dt,
  26.     i.registration_dt,
  27.     i.is_registration,
  28.     y.total_payment_amount
  29. from
  30.     user_attributes ua
  31. left join i on
  32.     ua.client_id = i.client_id
  33. left join y on
  34.     y.client_id = ua.client_id
  35. limit 10;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement