You have two queries:
One for the list of the students:
SELECT
id, age, num
FROM
students
And one for the count of students with the same age:
SELECT
age
, count(1)
FROM
students
GROUP BY
age
Now you have to combine these two queries:
You can JOIN one or more tables or subqueries. Lets do it:
SELECT
S.id, S.age, S.num, age.cnt
FROM
-- List of all students
(
SELECT
id, age, num
FROM
students
) S
-- Ages with student counts
INNER JOIN (
SELECT
age
, count(1) AS cnt
FROM
students
GROUP BY
age
) A
ON S.age = A.age
You can simplify the above query with removing the first subquery and use the students table instead:
SELECT
S.id, S.age, S.num, A.cnt
FROM
students S
-- Ages with student counts
INNER JOIN (
SELECT
age
, count(1) AS cnt
FROM
students
GROUP BY
age
) A
ON students.age = age.age
Now you can modify this sample query to achieve your goal.