select 
uid,
cnt
from(
select
uid,
count(distinct trace_id) as cnt,
row_number()over(order by count(distinct trace_id) desc,uid) as pdiff
from user_client_log
where
step="order"
group by uid
) as t 
where
t.pdiff<=3