ahmedrahil786

Amar - Coupon, Activated,redeems, MFTs

May 27th, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. select
  2. E.*,
  3. F.MFT
  4. from
  5. (select
  6. c.coupon_policy_id as cpid,
  7. c.comment as couponname,
  8. count(c.activated_at) as TotalApplied,
  9. count(c.used_at) as totalredeems
  10. from coupons c
  11. where c.coupon_policy_id in (656,655)
  12. and c.state = 'normal'
  13. group by 1
  14. order by 1 asc) E
  15.  
  16. left join
  17.  
  18. (select
  19. B.cpid as cpid,
  20. count(A.mid) as MFT
  21. from
  22. (select
  23. ch.member_id as mid
  24. from charges ch
  25. where ch.created_at + interval '8' hour >= '2019-5-1 00:00'
  26. and ch.kind = 'subscriptionFee') A
  27. join
  28. (select
  29. distinct c.member_id as mid,
  30. c.coupon_policy_id as cpid,
  31. c.comment
  32. from coupons c
  33. where c.coupon_policy_id in (656,655)
  34. and c.used_at is not null
  35. group by 1,2
  36. order by 1 asc) B
  37. on B.mid = A.mid
  38. group by B.cpid) F
  39. on E.cpid = F.cpid
Advertisement
Add Comment
Please, Sign In to add comment