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 renter_First_Reservation, H.Active_renters from
- (select
- extract('week' from u.created_at) as AWeek,
- count(distinct case when u.status not in ('null') then u.id end) as signup
- from users u
- group by 1) S
- left join
- (select
- extract('week' from uk.created_at) as AWeek,
- count(distinct case when uk.status not in ('null') then uk.user_id end) DocUploaded,
- count(distinct case when uk.status = 'approved' then uk.user_id end) DocApproved
- from user_kyc uk
- 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.user_id end) as Active_renters
- 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 A.userid end) as MFTs from
- ((select distinct b.id as bookingid, extract('week' from b.created_at) as AWeek, b.user_id userid
- from bookings b left join users u on u.id = b.user_id
- where b.status = 'completed'
- group by b.id
- order by b.id desc) A
- left join
- (select b.user_id as userid , min(b.id) as first_res
- from bookings b where b.status ='completed'
- group by userid
- order by 2 asc) B
- on B.userid = A.userid)
- group by A.AWeek) F
- on F.AWeek = S.AWeek
Advertisement
Add Comment
Please, Sign In to add comment