ahmedrahil786

Weekly MFTs Journey - Query Error

Jul 18th, 2019
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 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) in ('28', '27','26','25')
  8. and Year(c.created_at + interval 8 hour) = '2019'
  9. group by week) A
  10. left join
  11. (select
  12. distinct r.member_id as mid,
  13. weekofyear(r.start_at + interval '8' hour) as week,
  14. count(r.id) as resv
  15. from reservations r left join members m on m.id = r.member_id
  16. where weekofyear(r.start_at + interval '8' hour) = ('28', '27','26','25')
  17. and Year(r.start_at + interval 8 hour) = '2019'
  18. and r.state = 'completed'
  19. and m.state = 'normal'
  20. and m.imaginary = 'normal'
  21. group by r.member_id, week) B on A.mid = B.mid and A.week = B.week
  22. left join
  23. (select c.member_id as mid, weekofyear(c.created_at + interval '8' hour) as week, sum(c.amount) as gross from charges c
  24. 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) = ('28', '27','26','25')
  25. group by mid,week) E on A.mid = E.mid and A.week = E.Week
  26. left join
  27. (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
  28. where p.state = 'normal' and p.paid_type = 'coupon' and weekofyear(p.created_at + interval '8' hour) = ('28', '27','26','25')
  29. group by mid,week) F on F.mid = A.mid and A.week = F.week
  30. Group by A.week
Advertisement
Add Comment
Please, Sign In to add comment