with cte as( select university,age,count(distinct device_id ) as num from user_profile group by university,age ) select age,max(num) as max_cnt from cte group by age order by max_cnt desc,age desc