ahmedrahil786

Reservation State by date - Rahil

Nov 29th, 2019
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. set @startdate1 = '2019-06-01';
  2. set @startdate2 = '2019-12-01';
  3.  
  4. Select A.date,
  5. Count(A.rid) as rid,
  6. count(distinct case when A.state in ('completed', 'inUse','reserved') then A.rid end) as Completed_Bookings,
  7. count(distinct case when A.state in ('canceled') then A.rid end) as cancellations,
  8. count(distinct case when A.state in ('fail') then A.rid end) as failed
  9.  
  10. from
  11.  
  12. (select
  13. r.id as rid,
  14. r.state as state,
  15. date(r.start_at + interval 8 hour) as date
  16. from reservations r
  17. left join members m on r.member_id = m.id
  18. where r.start_at + interval 8 hour >= @startdate1
  19. and r.start_at + interval 8 hour <= NOW()
  20. and m.imaginary in ('sofam', 'normal')
  21. and r.member_id not in ('125', '127')
  22. group by rid) A
  23. group by 1
  24. order by 1 desc
Advertisement
Add Comment
Please, Sign In to add comment