ahmedrahil786

Reservations Split between 9 to 7 and 7 to 9 - Rahil

Dec 27th, 2019
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. set @startdate1 = '2019-01-01';
  2. set @startdate2 = '2019-12-31';
  3.  
  4. Select
  5. month(A.start_Date) as month,
  6. count(distinct A.rid) as resv,
  7. count(distinct case when A.resv_hour between 9 and 19 then A.rid end) as Booking_9_to_7,
  8. count(distinct case when A.resv_hour not between 9 and 19 then A.rid end) as Booking_Not_in_9_to_7,
  9. ROUND(count(distinct case when A.resv_hour between 9 and 19 then A.rid end)/count(distinct A.rid),2) as PCT_9_to_7,
  10. ROUND(count(distinct case when A.resv_hour not between 9 and 19 then A.rid end)/count(distinct A.rid),2) as PCT_9_to_7
  11. from
  12. (
  13. select distinct r.id as rid,
  14. Date(r.start_at + interval '8' hour) as start_Date,
  15. hour(r.created_at + interval '8' hour) as resv_hour
  16. from reservations r left join members m on r.member_id = m.id
  17. where r.state in ('completed')
  18. and r.start_at + interval 8 hour >= @startdate1
  19. and r.start_at + interval 8 hour <= @startdate2
  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