SQL/MySQL/Math/Max Min — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Версия 13:46, 26 мая 2010
Retrieving Maximum and Minimum Values
/*
mysql> Select * from StudentExam;
+-----------+------+------------+
| StudentID | Mark | Comments |
+-----------+------+------------+
| 10 | 76 | Java |
| 10 | 65 | C# |
| 10 | 79 | JavaScript |
+-----------+------+------------+
3 rows in set (0.04 sec)
mysql> /* Real command */
mysql> SELECT MAX(Mark) AS TopMark, MIN(Mark) AS BottomMark
-> FROM StudentExam
-> WHERE StudentID = 10;
+---------+------------+
| TopMark | BottomMark |
+---------+------------+
| 79 | 65 |
+---------+------------+
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");
Select * from StudentExam;
/* Real command */
SELECT MAX(Mark) AS TopMark, MIN(Mark) AS BottomMark
FROM StudentExam
WHERE StudentID = 10;