Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- set @startdate1 = '2019-01-01';
- set @startdate2 = '2019-12-31';
- Select
- month(A.start_Date) as month,
- count(distinct A.rid) as resv,
- count(distinct case when A.resv_hour between 9 and 19 then A.rid end) as Booking_9_to_7,
- count(distinct case when A.resv_hour not between 9 and 19 then A.rid end) as Booking_Not_in_9_to_7,
- 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,
- 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
- from
- (
- select distinct r.id as rid,
- Date(r.start_at + interval '8' hour) as start_Date,
- hour(r.created_at + interval '8' hour) as resv_hour
- from reservations r left join members m on r.member_id = m.id
- where r.state in ('completed')
- and r.start_at + interval 8 hour >= @startdate1
- and r.start_at + interval 8 hour <= @startdate2
- and m.imaginary in ('sofam', 'normal')
- and r.member_id not in ('125', '127')
- group by rid ) A
- group by 1
- order by 1 desc ;
Advertisement
Add Comment
Please, Sign In to add comment