Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- select
- m.id as memberid,
- dl.birthday as birthday,
- TIMESTAMPDIFF(YEAR, str_to_date(m.birthday, '%Y%m%d'), r.start_at) AS age,
- count(distinct r.id) as bookings
- from members m
- join driver_licenses dl
- on m.id = dl.member_id
- left outer join reservations r
- on r.member_id = m.id
- where r.state = 'completed'
- and CONVERT_TZ(m.created_at, '+00:00', '+8:00') >= '2018-1-01 00:00'
- and CONVERT_TZ(m.created_at, '+00:00', '+8:00') < '2019-09-01 00:00'
- and m.imaginary = 'normal'
- and m.state = 'normal'
- and dl.birthday != 0
- group by m.id
- order by bookings desc
Advertisement
Add Comment
Please, Sign In to add comment