ahmedrahil786

Weekly + Monthly Query for Payment Providers

Dec 23rd, 2019
786
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.92 KB | None | 0 0
  1. ############## Monthly Query for Payment Provider
  2.  
  3. set @startdate1 = '2019-01-01';
  4. set @startdate2 = '2019-12-31';
  5. Select
  6. month(A.start_Date) as month,
  7. year(A.start_Date) as year,
  8. Count(Distinct A.rid) as Total_attempts,
  9. count(distinct case when A.provider = 'mcp' then A.rid end) as Total_MCP,
  10. count(distinct case when A.provider = 'braintree' then A.rid end) as Total_braintree,
  11. count(distinct case when A.provider = 'grabpay' then A.rid end) as Total_grabpay,
  12. count(distinct case when A.provider = 'stripe' then A.rid end) as Total_stripe,
  13. count(distinct case when A.provider = 'mcp' and A.state not in ('fail') then A.rid end) as MCP_Good,
  14. count(distinct case when A.provider = 'braintree' and A.state not in ('fail') then A.rid end) as braintree_Good,
  15. count(distinct case when A.provider = 'grabpay' and A.state not in ('fail') then A.rid end) as grabpay_Good,
  16. count(distinct case when A.provider = 'stripe' and A.state not in ('fail') then A.rid end) as stripe_Good,
  17. count(distinct case when A.provider = 'mcp' and A.state in ('fail') then A.rid end) as MCP_failed,
  18. count(distinct case when A.provider = 'braintree' and A.state in ('fail') then A.rid end) as braintree_failed,
  19. count(distinct case when A.provider = 'grabpay' and A.state in ('fail') then A.rid end) as grabpay_failed,
  20. count(distinct case when A.provider = 'stripe' and A.state in ('fail') then A.rid end) as stripe_failed
  21. from
  22. (select
  23. distinct r.id as rid, r.member_id as mid, r.state as state, p.paid_type as type, pm.provider as provider,
  24. Date(r.created_at + interval '8' hour) as start_Date, p.paygate as provider_2
  25. from reservations r left join members m on r.member_id = m.id
  26. LEFT JOIN payment_methods pm ON r.payment_method_id = pm.id
  27. left join payments p on p.reservation_id = r.id
  28. where r.created_at + interval 8 hour >= @startdate1
  29. and r.created_at + interval 8 hour <= @startdate2
  30. and r.member_id not in ('125', '127')
  31. group by rid, type) A
  32. group by 1
  33. order by 1 desc;
  34.  
  35.  
  36. ######################## Weekly Query for Payment Provider
  37.  
  38. set @startdate1 = '2019-01-01';
  39. set @startdate2 = '2019-12-31';
  40. Select
  41. weekofyear(A.start_Date) as month,
  42. year(A.start_Date) as year,
  43. Count(Distinct A.rid) as Total_attempts,
  44. count(distinct case when A.provider = 'mcp' then A.rid end) as Total_MCP,
  45. count(distinct case when A.provider = 'braintree' then A.rid end) as Total_braintree,
  46. count(distinct case when A.provider = 'grabpay' then A.rid end) as Total_grabpay,
  47. count(distinct case when A.provider = 'stripe' then A.rid end) as Total_stripe,
  48. count(distinct case when A.provider = 'mcp' and A.state not in ('fail') then A.rid end) as MCP_Good,
  49. count(distinct case when A.provider = 'braintree' and A.state not in ('fail') then A.rid end) as braintree_Good,
  50. count(distinct case when A.provider = 'grabpay' and A.state not in ('fail') then A.rid end) as grabpay_Good,
  51. count(distinct case when A.provider = 'stripe' and A.state not in ('fail') then A.rid end) as stripe_Good,
  52. count(distinct case when A.provider = 'mcp' and A.state in ('fail') then A.rid end) as MCP_failed,
  53. count(distinct case when A.provider = 'braintree' and A.state in ('fail') then A.rid end) as braintree_failed,
  54. count(distinct case when A.provider = 'grabpay' and A.state in ('fail') then A.rid end) as grabpay_failed,
  55. count(distinct case when A.provider = 'stripe' and A.state in ('fail') then A.rid end) as stripe_failed
  56. from
  57. (select
  58. distinct r.id as rid, r.member_id as mid, r.state as state, p.paid_type as type, pm.provider as provider,
  59. Date(r.created_at + interval '8' hour) as start_Date, p.paygate as provider_2
  60. from reservations r left join members m on r.member_id = m.id
  61. LEFT JOIN payment_methods pm ON r.payment_method_id = pm.id
  62. left join payments p on p.reservation_id = r.id
  63. where r.created_at + interval 8 hour >= @startdate1
  64. and r.created_at + interval 8 hour <= @startdate2
  65. and r.member_id not in ('125', '127')
  66. group by rid, type) A
  67. group by 1
  68. order by 1 desc
Advertisement
Add Comment
Please, Sign In to add comment