```select recommend_user_id,count(recommend_user_id) count,MAX(time) time
from(
select i.user_id,u.recommend_user_id,i.time
from users u
right join (select b.user_id, b.time
from (select u.id, u.time
from users u
where time >= to_date('2017/12/01', 'yyyy/mm/dd')
and time < to_date('2018/01/19', 'yyyy/mm/dd')
and u.recommend_user_id <> 0) a
inner join (select user_id, MAX(time) time
from invests
where time >= to_date('2017/12/01', 'yyyy/mm/dd')
and time < to_date('2018/01/19', 'yyyy/mm/dd')
group by user_id
order by time) b
on a.id = b.user_id) i
on u.id = i.user_id
) group by recommend_user_id order by count desc,time