select item, gap, rank() over (partition by item order by gap) as rank_gap from custom_table order by item;
ORDER BY gap,item