먼저 테이블을 생성하겠습니다 -
mysql> create table DemoTable1875 ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Class varchar(20), Amount int ); Query OK, 0 rows affected (0.00 sec)
삽입 명령을 사용하여 테이블에 일부 레코드 삽입 -
mysql> insert into DemoTable1875(Class,Amount) values('X',750); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1875(Class,Amount) values('X',140); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1875(Class,Amount) values('X',450); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1875(Class,Amount) values('Y',6780); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1875(Class,Amount) values('Z',1350); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1875(Class,Amount) values('Z',2050); Query OK, 1 row affected (0.00 sec)
select 문을 사용하여 테이블의 모든 레코드 표시 -
mysql> select * from DemoTable1875;
이것은 다음과 같은 출력을 생성합니다 -
+----+-------+--------+ | Id | Class | Amount | +----+-------+--------+ | 1 | X | 750 | | 2 | X | 140 | | 3 | X | 450 | | 4 | Y | 6780 | | 5 | Z | 1350 | | 6 | Z | 2050 | +----+-------+--------+ 6 rows in set (0.00 sec)
다음은 행을 선택하는 쿼리입니다.
mysql> select Class,Min(Amount) from DemoTable1875 group by Class;
이것은 다음과 같은 출력을 생성합니다 -
+-------+-------------+ | Class | Min(Amount) | +-------+-------------+ | X | 140 | | Y | 6780 | | Z | 1350 | +-------+-------------+ 3 rows in set (0.00 sec)