ahmedrahil786

TTT (Members) - Renters Info for Dashboard

Dec 8th, 2019
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. select S.Aweek as Aweek, S.signup as hosts_Signup,D.DocUploaded, D.DocApproved, F.MFTs as renter_First_Reservation, H.Active_renters from
  2. (select
  3. extract('week' from u.created_at) as AWeek,
  4. count(distinct case when u.status not in ('null') then u.id end) as signup
  5. from users u
  6. group by 1) S
  7. left join
  8. (select
  9. extract('week' from uk.created_at) as AWeek,
  10. count(distinct case when uk.status not in ('null') then uk.user_id end) DocUploaded,
  11. count(distinct case when uk.status = 'approved' then uk.user_id end) DocApproved
  12. from user_kyc uk
  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.user_id end) as Active_renters
  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 A.userid end) as MFTs from
  24. ((select distinct b.id as bookingid, extract('week' from b.created_at) as AWeek, b.user_id userid
  25. from bookings b left join users u on u.id = b.user_id
  26. where b.status = 'completed'
  27. group by b.id
  28. order by b.id desc) A
  29. left join
  30. (select b.user_id as userid , min(b.id) as first_res
  31. from bookings b where b.status ='completed'
  32. group by userid
  33. order by 2 asc) B
  34. on B.userid = A.userid)
  35. group by A.AWeek) F
  36. on F.AWeek = S.AWeek
Advertisement
Add Comment
Please, Sign In to add comment