Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- set @start := '2019-11-1';
- select
- A.date,
- A.mid,
- B.rid as rid,
- B.coupon as coupon,
- B.car_name as car_name,
- B.created_hour as created_hour,
- B.region as region
- from
- (select
- distinct c.member_id as mid,
- date(c.created_at + interval '8' hour) as date
- 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,
- IFNULL(co.comment,"") as coupon,
- hour(r.created_at + interval '8' hour) as created_hour,
- cc.car_name,
- z.region as region
- from reservations r
- left join members m on r.member_id = m.id
- left join cars cr on cr.id = r.car_id
- left join car_classes cc on cc.id = cr.car_class_id
- left join coupons co on co.reservation_id = r.id
- left join reservation_appendixes ra on ra.reservation_id = r.id
- left join zones z on r.start_zone_id = z.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 A.mid
- order by 1 desc
Advertisement
Add Comment
Please, Sign In to add comment