ahmedrahil786

TTT - Hosts (Members) For Dashboard

Dec 8th, 2019
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. select S.Aweek as Aweek, S.signup as hosts_Signup,D.DocUploaded, D.DocApproved, F.MFTs as Host_First_Rent, H.Active_Hosts from
  2. (select
  3. extract('week' from l.created_at) as AWeek,
  4. count(distinct case when l.status not in ('null') then l.id end) as signup
  5. from listings l
  6. group by 1) S
  7. left join
  8. (select
  9. extract('week' from ld.created_at) as AWeek,
  10. count(distinct case when ld.status not in ('null') then ld.listing_id end) DocUploaded,
  11. count(distinct case when ld.status = 'approved' then ld.listing_id end) DocApproved
  12. from listing_documents ld
  13. group by 1) D
  14. on S.Aweek = D.Aweek
  15. left join
  16. (select
  17. extract('week' from b.created_at) as AWeek,
  18. count(distinct case when b.status in ('completed') then b.listing_id end) as Active_hosts
  19. from bookings b
  20. group by 1) H
  21. on H.Aweek = S.Aweek
  22. left join
  23. (select A.AWeek as AWeek, count(distinct case when B.first_res = A.bookingid then B.listing_id end) as MFTs from
  24. ((select distinct b.id as bookingid, extract('week' from b.created_at) as Aweek, b.listing_id as listing_id
  25. from bookings b
  26. where b.status = 'completed'
  27. group by b.id
  28. order by b.id desc) A
  29. left join
  30. (select b.listing_id as listing_Id , min(b.id) as first_res
  31. from bookings b where b.status ='completed'
  32. group by b.listing_id
  33. order by 2 asc) B
  34. on B.listing_Id = A.listing_Id)
  35. group by A.Aweek) F
  36. on F.AWeek = S.AWeek
Advertisement
Add Comment
Please, Sign In to add comment