ahmedrahil786

Coupon Info for Viny - Rahil

Mar 25th, 2020
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. set @startdate1 = '2017-1-1 00:00';
  2.  
  3. select
  4. E.*, IFNULL(B.MFTs,0) as MFTs
  5. from
  6. (select
  7. #LEFT(YEARWEEK(c.updated_at + interval '8' hour,3),4) AS year,
  8. #weekofyear(c.updated_at + interval '8' hour) as week,
  9. c.coupon_policy_id as cpid,
  10. c.comment as couponname,
  11. cp.enable_at as cp_enableat,
  12. cp.disable_at as cp_disableat,
  13. #c.promo_code_id as pcid,
  14. #pc.code as pc,
  15. count(c.activated_at + interval 8 hour) as TotalApplied,
  16. count(c.used_at + interval 8 hour) as totalredeems
  17. from coupons c
  18. left join promo_codes pc on c.coupon_policy_id = pc.coupon_policy_id
  19. left join coupon_policies cp on c.coupon_policy_id = cp.id
  20. where c.state = 'normal'
  21. and date (c.updated_at + interval '8' hour) >= @startdate1
  22. and c.coupon_policy_id in ('392')
  23. group by 1) E
  24. left join
  25. (select A.cpid as cpid, A.mid as mid,
  26. count(distinct case when A.cpid = '392' then A.mid end) as MFTs
  27. from
  28. (select
  29. distinct r.member_id as mid, min(r.id) as mrid, co.coupon_policy_id as cpid
  30. from reservations r left join members m on r.member_id = m.id
  31. left join coupons co on co.reservation_id = r.id
  32. where r.state in ('completed','inUse','reserved')
  33. and m.imaginary in ('sofam', 'normal')
  34. and r.member_id not in ('125', '127')
  35. group by 1) A
  36. where A.cpid in ('392')
  37. group by 1) B
  38. #on (E.year = B.year and E.week = B.week and E.cpid = B.cpid)
  39. on E.cpid = B.cpid
  40. WHERE E.cpid in ('392')
  41. group by E.cpid
  42. order by E.TotalApplied DESC
Advertisement
Add Comment
Please, Sign In to add comment