Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- set @start := '2017-04-01';
- select A.mid, A.age, A.resv, A.count, A.count_2 from
- (select
- distinct r.member_id as mid, count(r.id) as resv, (YEAR(r.start_at) - YEAR(m.birthday)) as age, count(distinct r.member_id) as count , count(distinct ca.member_id) as count_2
- from reservations r left join members m on r.member_id = m.id
- left join car_accidents ca on ca.reservation_id = r.id
- where r.state in ('completed')
- and r.return_at + interval 8 hour >= @start
- and m.imaginary in ('sofam', 'normal')
- and r.member_id not in ('125', '127')
- group by 1) A
- where A.resv >=2
Advertisement
Add Comment
Please, Sign In to add comment