ahmedrahil786

Weekly MFTs Journey -Rahil - Type by Week

Jul 18th, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. select A.mid, A.week, IFNULL(B.resv,1) as Lsf6,IFNULL(E.gross,0) as gross,IFNULL(F.coupon_spent,0) as coupon from
  2. (select
  3. distinct c.member_id as mid,
  4. weekofyear(c.created_at + interval '8' hour) as week
  5. from charges c
  6. where c.kind = 'subscriptionFee'
  7. and Weekofyear(c.created_at + interval 8 hour) = '25'
  8. and Year(c.created_at + interval 8 hour) = '2019') A
  9. left join
  10. (select
  11. distinct r.member_id as mid,
  12. weekofyear(r.start_at + interval '8' hour) as week,
  13. count(r.id) as resv
  14. from reservations r left join members m on m.id = r.member_id
  15. where weekofyear(r.start_at + interval '8' hour) = '25'
  16. and Year(r.start_at + interval 8 hour) = '2019'
  17. and r.state = 'completed'
  18. and m.state = 'normal'
  19. and m.imaginary = 'normal'
  20. group by r.member_id, week) B on A.mid = B.mid
  21. left join
  22. (select c.member_id as mid, weekofyear(c.created_at + interval '8' hour) as week, sum(c.amount) as gross from charges c
  23. where c.state='normal' and c.kind in ('rent','oneway','d2d','mileage') and c.created_at + interval '8' hour >= @start and weekofyear(c.created_at + interval '8' hour) = '25'
  24. group by mid,week) E on A.mid = E.mid
  25. left join
  26. (select p.member_id as mid, weekofyear(p.created_at + interval '8' hour) as week, IFNULL(p.amount,0) as coupon_Spent from payments p
  27. where p.state = 'normal' and p.paid_type = 'coupon' and weekofyear(p.created_at + interval '8' hour) = '25'
  28. group by mid,week) F on F.mid = A.mid
Advertisement
Add Comment
Please, Sign In to add comment