select m, max(r) from (select m, wm_concat(n) over (partition by m order by n) r from t) group by m ;