Untitled

 avatar
unknown
plain_text
2 years ago
733 B
5
Indexable
select
	all_counts.hotel,
	all_counts.days_in_waiting_list,
	all_counts.all_reservations,
	coalesce(cancelled_counts.cancelled_reservations, 0) as cancelled_reservations,
	(coalesce(cancelled_counts.cancelled_reservations, 0)::float / all_reservations) as cancelled_ratio
from (
	select hotel, days_in_waiting_list, count(*) as all_reservations
	from public.hotels_df
	group by hotel, days_in_waiting_list 
) as all_counts
left join (
	select hotel, days_in_waiting_list, count(*) as cancelled_reservations
	from public.hotels_df
	where is_canceled = 1
	group by hotel, days_in_waiting_list
) as cancelled_counts
on all_counts.hotel = cancelled_counts.hotel
and all_counts.days_in_waiting_list = cancelled_counts.days_in_waiting_list
Editor is loading...