Getting Column Averages : Average : Math SQL / MySQL


SQL / MySQL » Math » Average »

 

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,CommentsVALUES (10,76,'Java');
INSERT INTO StudentExam (StudentID,Mark,CommentsVALUES (10,65,'C#');
INSERT INTO StudentExam (StudentID,Mark,CommentsVALUES (10,79,'JavaScript');


/* Real command */
SELECT AVG(MarkAS AverageMark
FROM StudentExam
WHERE StudentID = 10;

           
       



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .

Follow Navioo On Twitter

SQL / MySQL

 Navioo Math
» Average