Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- set @start := '2017-01-01';
- 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,
- L.resv_start_date as resv_start_date, TIMESTAMPDIFF(minute,B.dl_uploaded_at_time,L.resv_start_time) as timediff_Resv
- from
- (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
- from
- (select
- distinct c.member_id as mid, weekofyear(c.created_at + interval '8' hour) as weekofyear, WEEKOFYEAR(c.created_at + interval '8' hour) as Week
- from charges c
- where c.kind = 'subscriptionFee' and c.created_at + interval '8' hour >= @start) A
- left join
- (select
- 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
- from reservations r
- join members m on r.member_id = m.id
- where m.imaginary in ('sofam', 'normal') and r.member_id not in ('125', '127') and r.start_at + interval '8' hour >= @start
- group by r.member_id) B
- on A.mid = B.mid
- group by 1) L
- left join
- (select
- dl.member_id as mid,
- min(id) as id,
- dl.state as state,
- dl.updated_at + interval 8 hour as dl_uploaded_at_time,
- date(dl.updated_at + interval 8 hour) as DL_uploaded_date,
- hour(dl.updated_at + interval 8 hour) as dl_created_hour
- from driver_licenses dl
- where dl.created_at + interval '8' hour >= @start
- and dl.state in ('approved','reject')
- group by 1
- order by 1 desc) B
- on L.mid = B.mid
- left join
- (select
- m.id as mid,
- m.created_at + interval 8 hour as created,
- date(m.created_at + interval 8 hour) as signup_date,
- hour(m.created_at + interval 8 hour) as signup_hour
- from members m
- where m.created_at + interval '8' hour >= @start
- and m.imaginary in ('sofam', 'normal')
- group by 1
- order by 1 desc) A
- on A.mid = B.mid
- where A.created is not null
Advertisement
Add Comment
Please, Sign In to add comment