Skip to content

STATISTICS

CREATE TABLE SampleTable (
ID INT NOT NULL PRIMARY KEY,
Name VARCHAR(50),
Age INT
);
INSERT INTO SampleTable (ID, Name, Age) VALUES
(1, 'John', 25),
(2, 'Jane', 30),
(3, 'Doe', 35),
(4, 'Smith', 40),
(5, 'Johnny', 45);
SELECT AVG(Age) AS AverageAge FROM SampleTable;
+------------+
| AverageAge |
+------------+
| 35.0 |
+------------+

In the above example, a table named SampleTable is first created with three columns: ID, Name, and Age. Five records are inserted into this table.

The SQL function AVG() is used to calculate the average value of the Age column in the SampleTable. The output of the SELECT AVG(Age) query is 35.0, which is the average age of all the people in the SampleTable.