Very Easy

Calculate average age

Calculate the average age of all students in the students table. Round the result to two decimal places.

SCHEMA

students

+------------+------------+-----------+-----+------------+
| student_id | first_name | last_name | age | class_code |
+------------+------------+-----------+-----+------------+
| 1          | Mike       | Chaplin   | 12  | 7A         |
| 2          | Emily      | Jackson   | 12  | 7A         |
| 3          | Robert     | Jackson   | 12  | 7A         |
| ...        | ...        | ...       | ... | ...        |
+------------+------------+-----------+-----+------------+
EXPECTED OUTPUT
+---------+
| avg_age |
+---------+
| 11.79   |
+---------+

Use AVG(col) to find the average value of col.

Use ROUND(num_to_round, decimal_places_to_round_to) to round a float.

SELECT ROUND(AVG(age), 2) FROM students

  • This field is required.