ahmedrahil786

MFTs Vs Total MFTs - Referral Dashboard

Mar 18th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. #set @start := '2019-1-1 00:00';
  2.  
  3. select
  4. A.dateofbooking,
  5. B.TotalReferralSignups,
  6. A.MFTs as ReferralMFTs,
  7. D.Signups,
  8. C.TotalMFTs,
  9. CAST((A.MFTs/B.TotalReferralSignups)*100 AS DECIMAL(18,2)) as PctConversion,
  10. CAST((A.MFTs/C.TotalMFTs)*100 AS DECIMAL(18,2)) as PctMFTContribution
  11.  
  12.  
  13. from(
  14. select
  15. dayofyear(c.created_at + interval '8' hour) as day,
  16. date(c.created_at + interval '8' hour) as dateofbooking,
  17. count(distinct case when c.kind = 'subscriptionFee' then c.member_id end) as MFTs
  18.  
  19. from charges c
  20.  
  21. join members m
  22. on m.id = c.member_id
  23.  
  24. join member_appendixes ma
  25. on ma.member_id = m.id and ma.recommender like '%@%'
  26.  
  27. where c.created_at + interval '8' hour >= @start
  28. and m.imaginary = 'normal'
  29.  
  30. group by 1) A
  31.  
  32.  
  33.  
  34. join (
  35. select
  36. dayofyear(m.created_at + interval '8' hour) as day,
  37. date(m.created_at + interval '8' hour) as dateofbooking,
  38. count(distinct m.id) as TotalReferralSignups
  39.  
  40. from members m
  41.  
  42. join member_appendixes ma
  43. on ma.member_id = m.id and ma.recommender like '%@%'
  44.  
  45. where m.created_at + interval '8' hour >= @start
  46. and m.imaginary = 'normal'
  47.  
  48. group by 1) B
  49. on B.day = A.day
  50.  
  51. join (
  52. select
  53. dayofyear(c.created_at + interval '8' hour) as day,
  54. date(c.created_at + interval '8' hour) as dateofbooking,
  55. count(distinct case when c.kind = 'subscriptionFee' then c.member_id end) as TotalMFTs
  56.  
  57. from charges c
  58.  
  59. join members m
  60. on m.id = c.member_id
  61.  
  62. where c.created_at + interval '8' hour >= @start
  63. and m.imaginary = 'normal'
  64.  
  65. group by 1) C
  66. on C.day = B.day
  67.  
  68. join (
  69. select
  70. dayofyear(m.created_at + interval '8' hour) as day,
  71. date(m.created_at + interval '8' hour) as dateofbooking,
  72. count(distinct m.id) as Signups
  73. from members m
  74. where m.created_at + interval '8' hour >= @start
  75. and m.imaginary = 'normal'
  76. group by 1) D
  77. on D.day = C.day
Advertisement
Add Comment
Please, Sign In to add comment