ahmedrahil786

TTT (DAILY) - HOSTS

Mar 5th, 2020
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. select S.date as date, S.signup as hosts_Signup,D.DocUploaded as DocUploaded , D.DocApproved as DocApproved,
  2. (D.DocUploaded - D.DocApproved) as DocRejected, F.MFTs as Host_First_Rent,
  3. H.Active_Hosts as Active_Hosts, P.bookings as bookings from
  4. (select
  5. date_trunc('day', l.created_at)::date as date,
  6. count(distinct case when l.status not in ('null') then l.id end) as signup
  7. from listings l
  8. group by 1) S
  9. left join
  10. (select
  11. date_trunc('day', ld.created_at)::date as date,
  12. count(distinct case when ld.status not in ('null') then ld.listing_id end) DocUploaded,
  13. count(distinct case when ld.status = 'approved' then ld.listing_id end) DocApproved
  14. from listing_documents ld
  15. group by 1) D
  16. on S.date = D.date
  17. left join
  18. (select
  19. date_trunc('day', b.created_at)::date as date,
  20. count(distinct case when b.status in ('completed') then b.listing_id end) as Active_hosts
  21. from bookings b
  22. group by 1) H
  23. on H.date = S.date
  24. left join
  25. (select A.date as date, count(distinct case when B.first_res = A.bookingid then B.listing_id end) as MFTs from
  26. ((select distinct b.id as bookingid,
  27. date_trunc('day', b.created_at)::date as date,
  28. b.listing_id as listing_id
  29. from bookings b
  30. where b.status = 'completed'
  31. group by b.id
  32. order by b.id desc) A
  33. left join
  34. (select b.listing_id as listing_Id , min(b.id) as first_res
  35. from bookings b where b.status ='completed'
  36. group by b.listing_id
  37. order by 2 asc) B
  38. on B.listing_Id = A.listing_Id)
  39. group by A.date) F
  40. on F.date = S.date
  41. left join
  42. (select
  43. date_trunc('day', b.created_at)::date as date,
  44. count(distinct b.id) as bookings
  45. from bookings b
  46. where b.status not IN ('cancelled', 'payment_failed', 'withdrawn', 'rejected', 'accepted')
  47. group by 1
  48. order by 1 desc) P
  49. on S.date = P.date
  50. order by 1 desc
Add Comment
Please, Sign In to add comment