ahmedrahil786

TTT (DAILY) - RENTERS

Mar 5th, 2020
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. select S.date as date, S.signup as renter_Signup, D.DocUploaded as DocUploaded,
  2. D.DocApproved as DocApproved, (D.DocUploaded - D.DocApproved) as DocRejected,
  3. F.MFTs as MFT_renter, H.Active_renters as Active_renters , P.bookings as bookings from
  4. (select
  5. date_trunc('day', u.created_at)::date as date,
  6. count(distinct case when u.status not in ('null') then u.id end) as signup
  7. from users u
  8. group by 1) S
  9. left join
  10. (select
  11. date_trunc('day', uk.created_at)::date as date,
  12. count(distinct case when uk.status not in ('null') then uk.user_id end) DocUploaded,
  13. count(distinct case when uk.status = 'approved' then uk.user_id end) DocApproved
  14. from user_kyc uk
  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.user_id end) as Active_renters
  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 A.userid end) as MFTs from
  26. ((select distinct b.id as bookingid,
  27. date_trunc('day', b.created_at)::date as date,
  28. b.user_id userid
  29. from bookings b left join users u on u.id = b.user_id
  30. where b.status = 'completed'
  31. group by b.id
  32. order by b.id desc) A
  33. left join
  34. (select b.user_id as userid , min(b.id) as first_res
  35. from bookings b where b.status not IN('cancelled', 'payment_failed', 'withdrawn', 'rejected', 'accepted')
  36. group by userid
  37. order by 2 asc) B
  38. on B.userid = A.userid)
  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
Advertisement
Add Comment
Please, Sign In to add comment