ahmedrahil786

Card Vs Grab pay - Sign Up to MFT Conversion Rate - Mr.Hoon

Oct 4th, 2019
522
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. set @start := '2019-05-01 00:00';
  2. Select A.month, A.cardupload as total_cardupload, ifnull(B.Debit,0) as card, IFNULL(C.grab,0) as grappay,
  3. P.MFTs as TotalMFT, P.card as Card_MFT, P.grabpay as grabpay_MFT
  4. from
  5. (select
  6. month(pm.created_at + interval '8' hour) as month,
  7. count(distinct pm.member_id) as cardupload
  8. from
  9. payment_methods as pm
  10. where pm.state = 'approved'
  11. and pm.created_at + interval '8' hour >= @start
  12. group by 1) A
  13. left Join
  14. (select
  15. month(pm.created_at + interval '8' hour) as month,
  16. count(distinct pm.member_id) as debit
  17. from
  18. payment_methods as pm
  19. where pm.state = 'approved'
  20. and pm.created_at + interval '8' hour >= @start
  21. and pm.card_type in ('debit','credit','prepaid')
  22. group by 1) B
  23. on A.month = B.month
  24. left join
  25. (select
  26. month(pm.created_at + interval '8' hour) as month,
  27. count(distinct pm.member_id) as grab
  28. from
  29. payment_methods as pm
  30. where pm.state = 'approved'
  31. and pm.created_at + interval '8' hour >= @start
  32. and pm.card_type in ('eWallet')
  33. group by 1) C
  34. on A.month = C.month
  35. left join
  36. (select month(I.date) as month , Count(Distinct I.mid) as MFTs,
  37. count(distinct case when I.paid_type in ('debit','credit','prepaid') then I.mid end) as card,
  38. count(distinct case when I.paid_type in ('eWallet') then I.mid end) as grabpay
  39. from
  40. (select A.return_date as date, A.rid2 as rid, A.mid as mid, if(rid2=firstRes,1,0) as mft, A.paid_type as paid_type from
  41. (select
  42. distinct r.id as rid2, r.member_id as mid, Date(r.return_at + interval '8' hour) as return_Date, pm.card_type as paid_type,
  43. ifnull((select min(id) from reservations where state='completed' and r.member_id=member_id group by member_id),0) as firstRes
  44. from reservations r left join members m on r.member_id = m.id
  45. left join payment_methods pm on pm.member_id = m.id
  46. where r.state in ('completed')
  47. and r.return_at + interval 8 hour >= @start
  48. and m.imaginary in ('sofam', 'normal')
  49. and r.member_id not in ('125', '127')
  50. and (YEAR(r.start_at) - YEAR(m.birthday)) < 100
  51. group by rid2) A ) I
  52. where I.mft = '1'
  53. group by 1) P
  54. on P.month = A.month
Advertisement
Add Comment
Please, Sign In to add comment