먼저 테이블을 생성하겠습니다 -
mysql> create table DemoTable1621 -> ( -> StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> StudentName varchar(20), -> StudentMarks int -> ); Query OK, 0 rows affected (1.69 sec)
삽입 명령을 사용하여 테이블에 일부 레코드 삽입 -
mysql> insert into DemoTable1621(StudentName,StudentMarks) values('Chris',45); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable1621(StudentName,StudentMarks) values('Bob',78); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1621(StudentName,StudentMarks) values('David',89); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable1621(StudentName,StudentMarks) values('Adam',87); Query OK, 1 row affected (0.20 sec)
select 문을 사용하여 테이블의 모든 레코드 표시 -
mysql> select * from DemoTable1621;
이것은 다음과 같은 출력을 생성합니다 -
+-----------+-------------+--------------+ | StudentId | StudentName | StudentMarks | +-----------+-------------+--------------+ | 1 | Chris | 45 | | 2 | Bob | 78 | | 3 | David | 89 | | 4 | Adam | 87 | +-----------+-------------+--------------+ 4 rows in set (0.00 sec)
다음은 집계 함수를 선택하는 쿼리입니다 -
mysql> select tblData.*,( select max(StudentMarks) from DemoTable1621) as MaximumMarks from DemoTable1621 tblData;
이것은 다음과 같은 출력을 생성합니다 -
+-----------+-------------+--------------+--------------+ | StudentId | StudentName | StudentMarks | MaximumMarks | +-----------+-------------+--------------+--------------+ | 1 | Chris | 45 | 89 | | 2 | Bob | 78 | 89 | | 3 | David | 89 | 89 | | 4 | Adam | 87 | 89 | +-----------+-------------+--------------+--------------+ 4 rows in set (0.00 sec)