Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- select S.Aweek as Aweek, S.signup as hosts_Signup,D.DocUploaded, D.DocApproved, F.MFTs as Host_First_Rent, H.Active_Hosts from
- (select
- extract('week' from l.created_at) as AWeek,
- count(distinct case when l.status not in ('null') then l.id end) as signup
- from listings l
- group by 1) S
- left join
- (select
- extract('week' from ld.created_at) as AWeek,
- count(distinct case when ld.status not in ('null') then ld.listing_id end) DocUploaded,
- count(distinct case when ld.status = 'approved' then ld.listing_id end) DocApproved
- from listing_documents ld
- group by 1) D
- on S.Aweek = D.Aweek
- left join
- (select
- extract('week' from b.created_at) as AWeek,
- count(distinct case when b.status in ('completed') then b.listing_id end) as Active_hosts
- from bookings b
- group by 1) H
- on H.Aweek = S.Aweek
- left join
- (select A.AWeek as AWeek, count(distinct case when B.first_res = A.bookingid then B.listing_id end) as MFTs from
- ((select distinct b.id as bookingid, extract('week' from b.created_at) as Aweek, b.listing_id as listing_id
- from bookings b
- where b.status = 'completed'
- group by b.id
- order by b.id desc) A
- left join
- (select b.listing_id as listing_Id , min(b.id) as first_res
- from bookings b where b.status ='completed'
- group by b.listing_id
- order by 2 asc) B
- on B.listing_Id = A.listing_Id)
- group by A.Aweek) F
- on F.AWeek = S.AWeek
Advertisement
Add Comment
Please, Sign In to add comment