Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- select S.date as date, S.signup as hosts_Signup,D.DocUploaded as DocUploaded , D.DocApproved as DocApproved,
- (D.DocUploaded - D.DocApproved) as DocRejected, F.MFTs as Host_First_Rent,
- H.Active_Hosts as Active_Hosts, P.bookings as bookings from
- (select
- date_trunc('day', l.created_at)::date as date,
- 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
- date_trunc('day', ld.created_at)::date as date,
- 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.date = D.date
- left join
- (select
- date_trunc('day', b.created_at)::date as date,
- 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.date = S.date
- left join
- (select A.date as date, count(distinct case when B.first_res = A.bookingid then B.listing_id end) as MFTs from
- ((select distinct b.id as bookingid,
- date_trunc('day', b.created_at)::date as date,
- 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.date) F
- on F.date = S.date
- left join
- (select
- date_trunc('day', b.created_at)::date as date,
- count(distinct b.id) as bookings
- from bookings b
- where b.status not IN ('cancelled', 'payment_failed', 'withdrawn', 'rejected', 'accepted')
- group by 1
- order by 1 desc) P
- on S.date = P.date
- order by 1 desc
Add Comment
Please, Sign In to add comment