Advertisement
ahmedrahil786

Card Rejected Cases - Rahil

Nov 21st, 2019
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. set @start1 := '2019-1-01 00:00';
  2. set @start2 := NOW();
  3. select Weekofyear(T.MFT_Date) as week,
  4. count(distinct T.mid) as total_card_rejected_cases,
  5. count(distinct case when T.resv = 0 then T.mid end) as Never_return,
  6. count(distinct case when T.resv > 0 then T.mid end) as Retained
  7. from
  8. (Select P.date as MFT_date, P.mid as mid, IFNULL(Q.resv,0) as resv from
  9. (select distinct I.mid as mid, I.date as date from
  10. #### Selecting the members whose first payment status is failed
  11. (Select A.mrid as mrid, p.paid_type as paid_type,A.way as way, A.mid as mid , A.date as date , A.state as state from
  12. #### Finding the first Transaction Details
  13. (select distinct r.member_id as mid, min(r.id) as mrid, date(r.start_at + interval 8 hour) as date , r.state as state, r.way as way
  14. from reservations r left join members m on m.id = r.member_id
  15. where m.imaginary in ('sofam', 'normal')
  16. and r.member_id not in ('125', '127')
  17. group by 1
  18. order by 1 desc) A
  19. left join payments p on p.reservation_id = A.mrid
  20. Where A.date >= @start1
  21. and A.date <= @start2
  22. group by 1,2
  23. order by 1 desc) I
  24. where I.state = 'fail') P
  25. #### Counting the number of Reservations
  26. left join
  27. (select distinct r.member_id as mid, count(r.id) as resv
  28. from reservations r join members m on m.id = r.member_id
  29. where m.imaginary in ('sofam', 'normal')
  30. and r.member_id not in ('125', '127')
  31. and r.state in ('completed')
  32. group by 1) Q
  33. on P.mid = Q.mid ) T
  34. group by 1
  35. order by 1 desc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement