ahmedrahil786

MFT,MAU Increase Query - Level 1 (All Type of Bookings)

Apr 15th, 2019
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. Select
  2. A.date,
  3. A.mid,
  4. B.carname,
  5. B.regionname,
  6. B.amount,
  7. Sum(A.TotalMFTs)
  8. from
  9.  
  10.  
  11. (select
  12. Date(c.created_at + interval '8' hour) as date,
  13. m.id as mid,
  14. count(distinct case when c.kind = 'subscriptionFee' then c.member_id end) as TotalMFTs
  15.  
  16. from charges c
  17.  
  18. join members m
  19. on m.id = c.member_id
  20.  
  21. left join reservations r
  22. on r.id = c.reservation_id
  23.  
  24.  
  25. where c.created_at + interval '8' hour >= '2019-3-1 00:00'
  26. and m.imaginary = 'normal'
  27. and c.kind = 'subscriptionFee'
  28. #and r.state = 'completed'
  29. Group by Date,mid) A
  30.  
  31. left join
  32.  
  33. (select
  34. distinct m.id as mid,
  35. min(Date(r.start_at + interval '8' hour)) as date,
  36. c.id as carid,
  37. cc.car_name as carname,
  38. z.id as zoneid,
  39. z.region as regionname,
  40. (p.amount) as amount
  41. from reservations r
  42.  
  43. left join members m
  44. on m.id = r.member_id
  45.  
  46. left join cars c
  47. on c.id = r.car_id
  48.  
  49. left join car_classes cc
  50. on cc.id = c.car_class_id
  51.  
  52. left join zones z
  53. on z.id = c.zone_id
  54.  
  55. join payments p
  56. on p.reservation_id = r.id
  57.  
  58. where r.start_at + interval '8' hour >= '2019-3-1 00:00'
  59. and r.state = 'completed'
  60.  
  61. group by mid) B
  62.  
  63. on A.mid = B.mid
  64.  
  65. group by A.Date,B.carname,B.regionname
Advertisement
Add Comment
Please, Sign In to add comment