ahmedrahil786

coupon vs non coupon users- Rahil

Jun 2nd, 2020
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. set @startdate1 = '2019-11-01';
  2. set @startdate2 = '2020-12-01';
  3. use socar_malaysia;
  4. select month(A.return_date) as return_date,
  5. count(distinct case when A.coupon is null then A.rid end) as non_Coupon_Users,
  6. count(distinct case when A.coupon is not null then A.rid end) as coupon_users,
  7. count(distinct case when A.coupon is null then A.rid end)/count(A.rid) as non_Coupon_Users_PCT,
  8. count(distinct case when A.coupon is not null then A.rid end)/count(A.rid) as coupon_users_PCT
  9. from
  10. (select
  11. distinct r.id as rid, r.member_id as mid,co.comment as coupon,
  12. Date(r.return_at + interval '8' hour) as return_Date
  13. from reservations r left join members m on r.member_id = m.id
  14. left join coupons co on co.reservation_id = r.id
  15. where r.state in ('completed')
  16. and r.return_at + interval 8 hour >= @startdate1
  17. and r.return_at + interval 8 hour <= @startdate2
  18. and m.imaginary in ('sofam', 'normal')
  19. and r.member_id not in ('125', '127')
  20. group by rid) A
  21. group by 1
Advertisement
Add Comment
Please, Sign In to add comment