ahmedrahil786

Members with accidents and without accidents > 2 Resv

May 12th, 2020
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. set @start := '2017-04-01';
  2. select A.mid, A.age, A.resv, A.count, A.count_2 from
  3. (select
  4. 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
  5. from reservations r left join members m on r.member_id = m.id
  6. left join car_accidents ca on ca.reservation_id = r.id
  7. where r.state in ('completed')
  8. and r.return_at + interval 8 hour >= @start
  9. and m.imaginary in ('sofam', 'normal')
  10. and r.member_id not in ('125', '127')
  11. group by 1) A
  12. where A.resv >=2
Advertisement
Add Comment
Please, Sign In to add comment