ahmedrahil786

Grabpay Query Leon

Jun 16th, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. set @start := '2019-5-22';
  2.  
  3. select
  4. A.Day,
  5. A.TotalMFTs,
  6. A.GrabMFT,
  7. A.mft_21,
  8. B.ActiveMembers,
  9. B.Bookings,
  10. B.NonCancelledBookings,
  11. B.NetRev,
  12. B.GrabPay,
  13. B.GrossRev,
  14. CAST((A.TOtalMFTs/B.ActiveMembers)*100 AS DECIMAL(18,2)) as MFT_DAUPct
  15. from (select
  16. DAY(c.created_at + interval '8' hour) as Day,
  17. count(distinct case when c.kind = 'subscriptionFee' and str_to_date(m.birthday, '%Y%m%d') >= NOW() - interval '21' year then c.member_id end) as mft_21,
  18. count(distinct case when c.kind = 'subscriptionFee' and pm.card_type = 'eWallet' then c.member_id end) as GrabMFT,
  19. count(distinct case when c.kind = 'subscriptionFee' then c.member_id end) as TotalMFTs
  20.  
  21. from charges c
  22. join members m
  23. on m.id = c.member_id
  24.  
  25. join payment_methods pm
  26. on pm.member_id = m.id
  27.  
  28. left outer join member_appendixes ma
  29. on ma.id = m.id
  30. where c.created_at + interval '8' hour >= @start
  31. #and c.created_at + interval '8' hour <= '2018-5-2 00:00
  32. and m.imaginary = 'normal'
  33. group by 1) A
  34. join (
  35. select
  36. DAY(r.created_at + interval '8' hour) as Day,
  37. count(distinct case when r.state NOT IN ('canceled', 'fail') then r.member_id end) as ActiveMembers,
  38. count(distinct case when r.state = 'completed' then r.id end) as Bookings,
  39. count(distinct case when r.state NOT IN ('canceled', 'fail') then r.id end) as NonCancelledBookings,
  40. count(distinct case when r.state = 'fail' then r.id end) as FailedBookings,
  41. count(distinct case when r.state = 'fail' then r.member_id end) as UniqueFailedsids,
  42. sum(case when p.state = 'normal' and p.paid_type IN ('card', 'eWallet') then p.amount end) as NetRev,
  43. sum(case when p.state = 'normal' and p.paid_type IN ('eWallet') then p.amount end) as GrabPay,
  44. sum(case when p.state = 'normal' then p.amount end) as GrossRev
  45. from reservations r
  46. join members m
  47. on m.id = r.member_id and m.email not like '%socar.my%' and m.imaginary = 'normal'
  48. join payments p
  49. on p.reservation_id = r.id
  50. where r.created_at + interval '8' hour >= @start
  51. and p.state = 'normal'
  52. group by 1
  53. order by 1 asc) B
  54. on B.Day = A.Day
  55. group by 1
  56. order by 1 asc
  57. ;
Add Comment
Please, Sign In to add comment