SELECT count(ap.appointment_id) as "viajes completados",pp.slave_id,sl.email,pp.amount,pp.create_dt,sl.phone
from pending_payment as pp
left join appointment as ap on pp.slave_id=ap.slave_id
LEFT join slave as sl on pp.slave_id=sl.slave_id
where pp.create_dt > '2018-18-01 00:00:00' AND pp.create_dt < '2019-01-31 23:59:59' and ap.status=9 and pp.amount<=20 and pp.status=0
GROUP by ap.slave_id
ORDER BY `viajes completados` DESC