ahmedrahil786

Daily Index - Signups MFT - Completed MFTs

Sep 3rd, 2019
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.20 KB | None | 0 0
  1. set @start := '2020-03-01';
  2.  
  3. select
  4. A.date,
  5. D.signups,
  6. C.DocUploaded,
  7. C.DocApproved,
  8. C.DocRejected,
  9. A.TotalMFTs as MFT_Transaction,
  10. T.mid as MFT_Trips,
  11. A.mft_21,
  12. IFNULL(O.MFT_Oneway,0) as MFT_Oneway,
  13. IFNULL(D2.MFT_d2d,0) as MFT_d2d,
  14. B.ActiveMembers,
  15. B.Bookings,
  16. round(E.Net_Rev,2) as Net_rev,
  17. round(E.gross_rev,2) as gross_rev,
  18. round(E.Coupon_Rev,2) as Coupon_Rev,
  19. round((E.Coupon_Rev/E.gross_rev)*100,2) as Coupon_Rate,
  20. CAST((A.TOtalMFTs/B.ActiveMembers)*100 AS DECIMAL(18,2)) as MFT_DAUPct,
  21. round(E.Net_Rev/B.Bookings,2) as Netrev_perbooking
  22. from (select
  23. date(c.created_at + interval '8' hour) as date,
  24. 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,
  25. count(distinct case when c.kind = 'subscriptionFee' then c.member_id end) as TotalMFTs
  26. from charges c
  27. join members m
  28. on m.id = c.member_id
  29. left outer join member_appendixes ma
  30. on ma.id = m.id
  31. where c.created_at + interval '8' hour >= @start
  32. #and c.created_at + interval '8' hour <= '2018-5-2 00:00
  33. and m.imaginary = 'normal'
  34. group by 1) A
  35. join (
  36. select
  37. date(r.return_at + interval '8' hour) as date,
  38. count(distinct case when r.state NOT IN ('canceled', 'fail') then r.member_id end) as ActiveMembers,
  39. count(distinct case when r.state = 'completed' then r.id end) as Bookings,
  40. count(distinct case when r.state NOT IN ('canceled', 'fail') then r.id end) as NonCancelledBookings,
  41. count(distinct case when r.state = 'fail' then r.id end) as FailedBookings,
  42. count(distinct case when r.state = 'fail' then r.member_id end) as UniqueFailedsids,
  43. sum(case when p.state = 'normal' and p.paid_type = 'card' then p.amount end) as NetRev,
  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.return_at + interval '8' hour >= @start
  51. and p.state = 'normal'
  52. group by 1
  53. order by 1 asc) B
  54. on B.date = A.date
  55.  
  56. join (select
  57. Date(dl.created_at + interval '8' hour) as Date,
  58. count(distinct case when dl.state not in ('noInput','null') then dl.member_id end) DocUploaded,
  59. count(distinct case when dl.state = 'approved' then dl.member_id end) DocApproved,
  60. count(distinct case when dl.state = 'reject' then dl.member_id end) DocRejected,
  61. count(distinct case when dl.gender = 'man' then dl.member_id end) MaleApproved,
  62. count(distinct case when dl.gender = 'woman' then dl.member_id end) FemaleApproved
  63. from driver_licenses dl
  64. join members m
  65. on m.id = dl.member_id
  66. where dl.created_at + interval '8' hour >= @start
  67. and m.imaginary = 'normal'
  68. group by 1) C
  69. on C.Date = A.Date
  70.  
  71. join
  72.  
  73. (select
  74. Date(m.created_at + interval '8' hour) as Date,
  75. count(distinct m.id) as signups
  76. from members m
  77. left outer join reservations r on
  78. r.member_id = m.id
  79. where m.created_at + interval '8' hour >= @start
  80. and m.imaginary = 'normal'
  81. group by 1 ) D
  82. on D.Date = A.Date
  83.  
  84. Join
  85.  
  86. (select
  87. A.date as date,
  88. A.rev as gross_rev,
  89. B.coupon as Coupon_Rev,
  90. A.rev - B.coupon as Net_Rev
  91. from
  92. (select
  93. date(r.return_at + interval '8' hour) as date,
  94. sum(c.amount) as rev
  95. from charges c
  96. join reservations r
  97. on c.reservation_id = r.id
  98. where c.state = 'normal' and c.kind IN ('rent' , 'oneway', 'd2d', 'mileage')
  99. group by 1) A
  100. join
  101. (select
  102. date(r.return_at + interval '8' hour) as date,
  103. IFNULL(sum(p.amount),0) as coupon
  104. from payments p
  105. join reservations r on p.reservation_id = r.id
  106. where p.state = 'normal' and p.paid_type = 'coupon'
  107. group by 1) B
  108. on A.date = B.date) E
  109. on E.date = A.date
  110. left join
  111. (Select (A.date) as date, Count(A.rid) as MFT_Oneway from
  112. (select FB.rid2 as rid, FB.mid as mid, FB.way as way, FB.date as date from
  113. (select r.id as rid2 ,r.start_zone_id as stid, r.end_zone_id as edid,
  114. date(r.start_at + interval '8' hour) as date,
  115. fbo.mid as mid,fbo.rid,fbo.way as way from
  116. reservations r
  117. join
  118. (select
  119. fbi.mid as mid,fbi.rid as rid,fbi.way as way from
  120. (select
  121. distinct r.member_id as mid, min(r.id) as rid, r.way as way
  122. from reservations r join members m on m.id = r.member_id
  123. where r.state = 'completed' and m.imaginary = 'normal' and m.email not like '%socar.my%' group by r.member_id) fbi
  124. where fbi.way in ('oneway','onewayReturn') ) fbo on fbo.rid = r.id
  125. where r.start_zone_id in ('244','245') or r.end_zone_id in ('244','245') )FB
  126. where date(FB.date + interval '8' hour) >= '2020-01-01') A group by date order by date desc ) O
  127. on O.date = A.date
  128. left join
  129. (Select L.date as date, Count(L.mid) as mid from
  130. (Select B.date as date, B.mid as mid from
  131. (select distinct c.member_id as mid, date(c.created_at + interval '8' hour) as date
  132. from charges c left join members m on m.id = c.member_id
  133. where c.kind = 'subscriptionFee'
  134. and m.imaginary in ('normal','sofam')
  135. and date(c.created_at + interval '8' hour) >= '2019-01-01') A
  136. left join
  137. (Select Distinct r.member_id as mid, date(r.return_at + interval '8' hour) as date
  138. from reservations r left join members m on m.id = r.member_id
  139. where m.imaginary in ('normal','sofam')
  140. and date(r.return_at + interval '8' hour) >= '2019-01-01'
  141. and r.state in ('completed','inUse', 'reserved')
  142. group by 1) B
  143. on B.mid = A.mid
  144. group by 2
  145. order by 1 desc) L
  146. Group by 1
  147. order by 1 desc) T
  148. on T.date = A.date
  149. left join
  150. (Select (A.date) as date, Count(A.rid) as MFT_d2d from
  151. (select FB.rid2 as rid, FB.mid as mid, FB.way as way, FB.date as date from
  152. (select r.id as rid2 ,r.start_zone_id as stid, r.end_zone_id as edid,
  153. date(r.start_at + interval '8' hour) as date,
  154. fbo.mid as mid,fbo.rid,fbo.way as way from
  155. reservations r
  156. join
  157. (select
  158. fbi.mid as mid,fbi.rid as rid,fbi.way as way from
  159. (select
  160. distinct r.member_id as mid, min(r.id) as rid, r.way as way
  161. from reservations r join members m on m.id = r.member_id
  162. where r.state = 'completed' and m.imaginary = 'normal' and m.email not like '%socar.my%' group by r.member_id) fbi
  163. where fbi.way in ('d2d') ) fbo on fbo.rid = r.id)FB
  164. where date(FB.date + interval '8' hour) >= '2020-01-01') A group by date order by date desc ) D2
  165. on D2.date = A.date
  166. group by 1
  167. order by 1 desc
  168. ;
Advertisement
Add Comment
Please, Sign In to add comment