select
id,
age = (select max(age) from test where age <> (select max(age) from test))
from test
group by id,age
order by id desc ,age desc
select
id,
age = (select max(age) from test where age <> (select max(age) from test) and age <> (select Distinct age = (select max(age) from test where age <> (select max(age) from test)) from test))
from test
group by id,age
order by id desc ,age desc