让我们首先创建一个表。在这里,我们使用ENUM设置状态-
mysql> create table DemoTable2037 -> ( -> StudentId int, -> status enum('Active','Inactive') -> );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable2037 values(99,'Active'); mysql> insert into DemoTable2037 values(99,'Inactive'); mysql> insert into DemoTable2037 values(100,'Inactive'); mysql> insert into DemoTable2037 values(99,'Active'); mysql> insert into DemoTable2037 values(100,'Inactive'); mysql> insert into DemoTable2037 values(101,'Active'); mysql> insert into DemoTable2037 values(101,'Active');
使用select语句显示表中的所有记录-
mysql> select *from DemoTable2037;
这将产生以下输出-
+-----------+----------+ | StudentId | status | +-----------+----------+ | 99 | Active | | 99 | Inactive | | 100 | Inactive | | 99 | Active | | 100 | Inactive | | 101 | Active | | 101 | Active | +-----------+----------+ 7 rows in set (0.00 sec)
这是查询以选择具有活动状态的记录-
mysql> select StudentId,status -> from DemoTable2037 where status='Active' -> group by StudentId;
这将产生以下输出-
+-----------+--------+ | StudentId | status | +-----------+--------+ | 99 | Active | | 101 | Active | +-----------+--------+ 2 rows in set (0.00 sec)