ahmedrahil786

Rentals - SYNC - LOUI - Key Index Dashboard

Jul 25th, 2019
328
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. set @start := '2018-12-31 00:00';
  2.  
  3. select
  4. A.month,
  5. C.Bookings as rentals
  6.  
  7. from (select
  8. month(m.created_at + interval '8' hour) as month,
  9. count(distinct m.id) as signups
  10. from members m
  11. left outer join reservations r on r.member_id = m.id
  12. where m.created_at + interval '8' hour >= @start
  13. and m.imaginary = 'normal'
  14. group by 1 ) A
  15.  
  16. #### Replace the Code with present code to SYNC Numbers with loui
  17. join (select
  18. month(r.return_at + interval '8' hour) as month,
  19. count(distinct case when r.state = 'completed' then r.member_id end) as ActiveMembers,
  20. count(distinct case when r.state = 'completed' then r.id end) as Bookings,
  21. sum(timestampdiff(minute,CONVERT_TZ(r.start_at, '+00:00', '+8:00'), CONVERT_TZ(r.end_at, '+00:00', '+8:00'))/60) as ridelength,
  22. sum(G.amount) as Charges
  23. from reservations r
  24. left outer join (select
  25. ch.reservation_id as rid,
  26. sum(ch.amount) as amount
  27. from payments ch
  28. group by 1
  29. ) G on G.rid = r.id
  30. join members m on m.id = r.member_id
  31. where r.return_at + interval '8' hour >= @start
  32. and m.imaginary in ('normal','sofam')
  33. and r.state = 'completed'
  34. and r.start_zone_id not in (2,3,378,712)
  35. group by 1) C on
  36. C.month = A.month
  37.  
  38. group by 1
  39.  
  40. order by 1 asc;
Advertisement
Add Comment
Please, Sign In to add comment