ahmedrahil786

Time diff - Signups vs Doc upload vs MFTs

Mar 13th, 2020
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. set @start := '2017-01-01';
  2.  
  3. Select L.mid, A.created, A.signup_date, A.signup_hour, B.state,B.dl_uploaded_at_time,B.DL_uploaded_date,B.dl_created_hour, TIMESTAMPDIFF(minute,A.created,B.dl_uploaded_at_time) as timediff,
  4. L.resv_start_date as resv_start_date, TIMESTAMPDIFF(minute,B.dl_uploaded_at_time,L.resv_start_time) as timediff_Resv
  5.  
  6. from
  7.  
  8. (select A.mid as mid, B.rid as rid , B.resv_start_date as resv_start_date,B.resv_start_hour as resv_start_hour, B.resv_start_time as resv_start_time
  9. from
  10. (select
  11. distinct c.member_id as mid, weekofyear(c.created_at + interval '8' hour) as weekofyear, WEEKOFYEAR(c.created_at + interval '8' hour) as Week
  12. from charges c
  13. where c.kind = 'subscriptionFee' and c.created_at + interval '8' hour >= @start) A
  14. left join
  15. (select
  16. distinct r.member_id as mid, min(r.id) as rid, date(r.created_at + interval 8 hour) as resv_start_date, Hour(r.created_at + interval 8 hour) as resv_start_hour, r.created_at + interval 8 hour as resv_start_time
  17. from reservations r
  18. join members m on r.member_id = m.id
  19. where m.imaginary in ('sofam', 'normal') and r.member_id not in ('125', '127') and r.start_at + interval '8' hour >= @start
  20. group by r.member_id) B
  21. on A.mid = B.mid
  22. group by 1) L
  23. left join
  24. (select
  25. dl.member_id as mid,
  26. min(id) as id,
  27. dl.state as state,
  28. dl.updated_at + interval 8 hour as dl_uploaded_at_time,
  29. date(dl.updated_at + interval 8 hour) as DL_uploaded_date,
  30. hour(dl.updated_at + interval 8 hour) as dl_created_hour
  31. from driver_licenses dl
  32. where dl.created_at + interval '8' hour >= @start
  33. and dl.state in ('approved','reject')
  34. group by 1
  35. order by 1 desc) B
  36. on L.mid = B.mid
  37. left join
  38. (select
  39. m.id as mid,
  40. m.created_at + interval 8 hour as created,
  41. date(m.created_at + interval 8 hour) as signup_date,
  42. hour(m.created_at + interval 8 hour) as signup_hour
  43. from members m
  44. where m.created_at + interval '8' hour >= @start
  45. and m.imaginary in ('sofam', 'normal')
  46. group by 1
  47. order by 1 desc) A
  48. on A.mid = B.mid
  49. where A.created is not null
Advertisement
Add Comment
Please, Sign In to add comment