Getting Column Averages
/*
mysql> SELECT AVG(Mark) AS AverageMark
-> FROM StudentExam
-> WHERE StudentID = 10;
+-------------+
| AverageMark |
+-------------+
| 73.3333 |
+-------------+
1 row in set (0.00 sec)
*/
/* Create table */
Drop TABLE StudentExam;
CREATE TABLE StudentExam (
StudentID INT NOT NULL,
Mark INT,
Comments VARCHAR(255)
)TYPE = InnoDB;
/* Insert data */
INSERT INTO StudentExam (StudentID,Mark,Comments) VALUES (10,76,'Java');
INSERT INTO StudentExam (StudentID,Mark,Comments) VALUES (10,65,'C#');
INSERT INTO StudentExam (StudentID,Mark,Comments) VALUES (10,79,'JavaScript');
/* Real command */
SELECT AVG(Mark) AS AverageMark
FROM StudentExam
WHERE StudentID = 10;
Related examples in the same category