ahmedrahil786

MFT , Transaction Date vs Completed Date - Rahil for Amri

Sep 17th, 2019
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. set @start := '2019-1-1';
  2.  
  3. select P.mid, P.created_date as MFT_date, IFNULL(Q.completed_date, "0") as completed_date from
  4.  
  5. (select distinct c.member_id as mid,
  6. date(c.created_at + interval 8 hour) as created_date
  7. from charges c join members m on m.id = c.member_id
  8. where c.created_at + interval '8' hour >= @start
  9. and m.imaginary in ('sofam', 'normal')
  10. and c.kind = 'subscriptionFee') P
  11. left join
  12. (Select A.mid as mid, A.first_rid as first_rid, B.date as completed_date from
  13. (select distinct r.member_id as mid,
  14. min(r.id) as first_rid
  15. from reservations r join members m on m.id = r.member_id
  16. where m.imaginary in ('sofam', 'normal')
  17. and r.state = 'completed'
  18. group by 1) A
  19. left join
  20. (select distinct r.id as rid,
  21. date(r.created_at + interval '8' hour) as date
  22. from reservations r ) B
  23. on B.rid = A.first_rid ) Q
  24. on Q.mid = P.mid
Advertisement
Add Comment
Please, Sign In to add comment